+ Post New Thread
Results 1 to 7 of 7
Coding Thread, VBS Check character in Coding and Web Development; Hi all, First post on here, so hoping that I have it right. I have the following code (Written in ...
  1. #1
    T_Noble's Avatar
    Join Date
    Jan 2010
    Location
    Gloucestershire
    Posts
    13
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    VBS Check character

    Hi all,

    First post on here, so hoping that I have it right.

    I have the following code (Written in VBS):
    Code:
    ' 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

  2. #2
    Gerry's Avatar
    Join Date
    Jun 2007
    Location
    North Wales
    Posts
    431
    Thank Post
    60
    Thanked 38 Times in 35 Posts
    Rep Power
    23
    This should get you the first character.

    Code:
    FirstCharacter = Left(strLUsername, 1)
    Left Function

  3. #3
    T_Noble's Avatar
    Join Date
    Jan 2010
    Location
    Gloucestershire
    Posts
    13
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Could I use the following (Working on code from both the above replies)?

    Code:
    ' 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

  4. #4
    Gerry's Avatar
    Join Date
    Jun 2007
    Location
    North Wales
    Posts
    431
    Thank Post
    60
    Thanked 38 Times in 35 Posts
    Rep Power
    23
    This should work:

    Code:
    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.

  5. Thanks to Gerry from:

    T_Noble (14th January 2010)

  6. #5
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    41
    You could use isnumeric:

    Code:
    ' 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.

  7. Thanks to apeo from:

    T_Noble (14th January 2010)

  8. #6
    T_Noble's Avatar
    Join Date
    Jan 2010
    Location
    Gloucestershire
    Posts
    13
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Both the thanked replies work well.

    Code:
    ' 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

    Code:
    If FirstCharacter >= "1" And FirstCharacter <= "9" Then
    	StrType = "student"
    Else
    	StrType = "staff"
    End If
    Kind Regards All

    Tom

  9. #7
    ajb
    ajb is offline
    ajb's Avatar
    Join Date
    Jan 2010
    Location
    East Midlands
    Posts
    6
    Thank Post
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    0
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 13
    Last Post: 11th June 2009, 11:38 PM
  2. Chinese Character Encoding Outlook 2007
    By robbied69 in forum Windows
    Replies: 0
    Last Post: 29th April 2008, 02:07 PM
  3. [CLOSED] Bug/Error: Special Character Bug
    By Gatt in forum EduGeek.net Site Problems
    Replies: 3
    Last Post: 19th February 2008, 10:42 AM
  4. Replies: 29
    Last Post: 7th July 2007, 01:47 PM
  5. Chinese character input - language bar woes
    By Ravening_Wolf in forum Windows
    Replies: 4
    Last Post: 2nd July 2007, 09:22 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •