ajetrumpet
Banned
- Local time
- Today, 08:37
- Joined
- Jun 22, 2007
- Messages
- 5,638
Folks,
What does the line strUserName = String$(254, 0) do in the code? What is the dollar sign for? What does it do? Why, when I try to extract the windows user name from my machine, do I get an error that tells me the String function is not in the library? Thank you...
EDIT
A picture is attached with an interesting error when I was testing Environ("username") in the immediate window...
What does the line strUserName = String$(254, 0) do in the code? What is the dollar sign for? What does it do? Why, when I try to extract the windows user name from my machine, do I get an error that tells me the String function is not in the library? Thank you...
Code:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
[COLOR="Red"]strUserName = String$(254, 0)[/COLOR]
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If ( lngX > 0 ) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
EDIT
A picture is attached with an interesting error when I was testing Environ("username") in the immediate window...
Attachments
Last edited: