T_Noble Posted January 14, 2010 Posted January 14, 2010 Hi all, First post on here, so hoping that I have it right. I have the following code (Written in VBS): ' Gather required information strLUsername = net.username strLComputer = net.computername strLDate = CStr(Date) strLTime = CStr(Time) strOU = LCase(GetDN) If InStr(staff, user.Description) Then strType = "staff" Else strType = "student" End If I want it to do the following: If First Character of the username is an integer (1-9) Then StrType = "student" Else StrType = "staff" End If Thanks for any replies in advanced. Kind Regards Tom
Gerry Posted January 14, 2010 Posted January 14, 2010 This should get you the first character. FirstCharacter = Left(strLUsername, 1) Left Function
T_Noble Posted January 14, 2010 Author Posted January 14, 2010 Could I use the following (Working on code from both the above replies)? ' Gather required information strLUsername = net.username strLComputer = net.computername strLDate = CStr(Date) strLTime = CStr(Time) strOU = LCase(GetDN) FirstCharacter = Left(strLUsername, 1) If FirstCharacter = "[1-9]" Then strType = "student" Else strType = "staff" End If Regards Tom
Gerry Posted January 14, 2010 Posted January 14, 2010 This should work: If FirstCharacter >= "1" And FirstCharacter <= "9" Then StrType = "student" Else StrType = "staff" End If Here's a couple of sites that have helped me: VBScript Tutorial Script Center And you might want to check this script editor out: VbsEdit - Award-winning VBScript Editor - VBS editor - VBScript debugger - VBS debugger It has some nag screens, but the trial period never runs out. 1
apeo Posted January 14, 2010 Posted January 14, 2010 You could use isnumeric: ' Gather required information strLUsername = net.username strLComputer = net.computername strLDate = CStr(Date) strLTime = CStr(Time) strOU = LCase(GetDN) FirstCharacter = Left(strLUsername, 1) If isNumeric(FirstCharacter) Then strType = "student" Else strType = "staff" End If Think that should work but i havent tested it. 1
T_Noble Posted January 14, 2010 Author Posted January 14, 2010 Both the thanked replies work well. ' Gather required information strLUsername = net.username strLComputer = net.computername strLDate = CStr(Date) strLTime = CStr(Time) strOU = LCase(GetDN) FirstCharacter = Left(strLUsername, 1) If isNumeric(FirstCharacter) Then strType = "student" Else strType = "staff" End If and If FirstCharacter >= "1" And FirstCharacter <= "9" Then StrType = "student" Else StrType = "staff" End If Kind Regards All Tom
ajb Posted January 14, 2010 Posted January 14, 2010 Forgive me for appearing a little pernickety but... The IsNumeric function will return True when FirstCharacter is equal to "0" won't it? Maybe this isn't quite the behaviour you wanted. Cheers, Andy.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now