Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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.

  • Thanks 1
Posted

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

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...