Link to home
Start Free TrialLog in
Avatar of holemania
holemania

asked on

VB.Net - Windows UserName index and length error

I have a Vb.Net application that I want to track the user who logs into Windows.  I am keeping this information in a table that has only 8 characters long.  When I do the following, I am getting the error.

Index and Length must refer to a location within the string.  Parameter name: length

Dim strUser String = System.Environment.Username.Substring(0,8).ToUpper

Open in new window


I did a length and the name "blakie" is 13 characters long.  So is there something that is padding in that string?  I also tried to trim, but it's still come up as 13 characters long.
SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of holemania
holemania

ASKER

Yeah, not sure why it is giving me that error.  When I did the following I am getting length of 13 which is a bit odd.

Dim strUser As String = System.Environment.UserName.Substring(0, 8).ToUpper

Msgbox(strUser.Length)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like when I add the "If" statement to evaluate the length, the error went away.  Thanks.