Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get User Info (2000)

    I have a small piece of code (module GET_USER) that was sent to me from someone else in our office. It works as designed for them...but I get a compile error. This code is designed to extract the user id of the person logged into the machine. I get an expected end of statement error on the opon paren on the Alias line. I've tried to rearrange the items to no avail. I was hoping you may have some insight...thanks...

    CODE FOLLOWS:

    Option Compare Database
    Option Explicit

    Public Declare Function GetUserName Lib "advapi32.dll" ()
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) as Long


    Function GetUser() As String

    Dim lpBuff As String * 255

    Dim ret As Long, UserName As String

    ret = GetUserName(lpBuff, 255)

    GetUser = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)

    End Function

  2. #2
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get User Info (2000)

    This:
    Public Declare Function GetUserName Lib "advapi32.dll" ()
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) as Long

    Should be:
    Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) as Long

    all one line, no parenthesis.
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  3. #3
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get User Info (2000)

    Thanks...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get User Info (2000)

    Or, if you want to keep the code on two lines for aesthetic purposes, use a line continuation character _:
    <code>
    Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) as Long</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •