Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesn't this line work? 1

Status
Not open for further replies.

bbarz

IS-IT--Management
Dec 15, 2004
7
0
0
US
OK, so this is basically an operator precedence issue that hopefully someone could explain to me. I want to add the following code to my login script to assist in mapping drives.

strDrive = Chr(Asc(Left(strDrive,1)-1)) & ":"

strDrive initially holds a 2 char string containing a drive letter and a colon (i.e. "W:"). The idea here is to pull just the drive letter from the string, convert that letter into its ascii code, subtract 1 from that value, convert that back into a character and finally append the colon back to it. After all this strDrive should contain "V:" but I get a type mismatch error when running the script. If I break the line out and read each step into a variable as below, it works.

strLetter = Left(strDrive,1)
strAscii = Asc(strLetter) -1
strNextLetter = Chr(strAscii)
strDrive = strNextLetter & ":"

I'm sure this has something to do with the order of operation and at this point I'm just being stubborn. Is there a way to accomplish this in a single line of code?

 
You probably should break it out so that if anyone ever has to update or edit your code it will be more readable.
 
It should also be the following

strDrive = Chr(Asc(Left(strDrive,1))-1) & ":
 
Doh! Thanks and good point about the readability.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top