PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Validating characters in a string-VBForums
Results 1 to 36 of 36

Thread: Validating characters in a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Validating characters in a string

    How do I validate characters in a string? i.e. The user must enter something into a text box, 8 characters long. The first 3 characters must be TPX, and the remaining 5 must be a number. Thanks

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: Validating characters in a string

    Then Regular Expression is the best Choice.

    This pattern will do the trick..

    Code:
    TFXd{5}

    Regular Expressions with VS
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: Validating characters in a string

    Then Regular Expression is the best Choice.

    This pattern will do the trick..

    Code:
    TFXd{5}

    Regular Expressions with VS
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    how exactly do I use it in my validation code though? I think I have to demonstrate it using a loop too, not a regular expression. Sorry, just a beginner
    Last edited by Calvin1991; Apr 16th, 2010 at 03:39 AM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    anyone? need this ASAP!

  6. #6
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: Validating characters in a string

    An alternative to Regex would be to use the Substring method to check if the first 3 characters are equal to "TPX", then check if the last 5 characters are numerical by using Integer.TryParse or IsNumeric.

    If you need to use a loop though: loop through each character individually and use a counter to determine which position it is in. Now you can check the appropriate format of the said characters one by one.
    "The only thing that interferes with my learning is my education."

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    So, seeing its 8 characters in length..

    For ICounter = 1 to 7

    then what? how do I check char (0) = T char (1) = P etc and the last 5 are numeric?

  8. #8
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,958

    Re: Validating characters in a string

    vb.net Code:
    1. Dim three as string = originalString.SubString(0,3)
    2. If three = "TPX" Then MsgBox("OK")

    RegEx Mode:
    vb.net Code:
    1. Dim reg As New Regex("^TPX[0-9]{5}$")
    2. Dim m As Match = reg.Match(login)
    3. If m.Success Then MsgBox("OK")
    Last edited by mickey_pt; Apr 16th, 2010 at 05:55 AM. Reason: Posted incomplete

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Thanks the first code works and all. Is there any possible way to do this with a loop though?

  10. #10
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,958

    Re: Validating characters in a string

    To check each individual char just use the the index property...
    vb.net Code:
    1. If originalString(0) = "T"c Then
    2. '...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  11. #11
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: Validating characters in a string

    Quote Originally Posted by Calvin1991 View Post
    Thanks the first code works and all. Is there any possible way to do this with a loop though?
    Loops will kill the performance. Always go for Regex or substring method
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Eh sorry im really bad. This is what im trying, and I get a program crash with the error, Index and length must refer to a location within the string.

    Dim sDutyManager As String
    sDutyManager = txtDutyManager.Text
    Dim TPX As String = sDutyManager.Substring(0, 3)

    If TPX <> "TPX" Then
    sErrorMessage = sErrorMessage & "Duty Manager must start with TPX" & vbCrLf
    bErrorOccurred = True
    End If

  13. #13
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,958

    Re: Validating characters in a string

    THat's beacuase the txtDutyManager.TextLength it's less than 3...
    Just check for the size
    vb.net Code:
    1. If txtDutyManager.TextLength <> 8 Then 'This is the size of your string
    2. 'Not good
    3. Else
    4. 'Have 8 chars can check if it's valid...
    5. End If

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Private Sub ValidateDayDetails()

    Dim sErrorMessage As String
    Dim bErrorOccurred As Boolean = False
    Dim sDutyManager As String
    Dim TPX As String = sDutyManager.Substring(0, 3)


    sDutyManager = txtDutyManager.Text
    sErrorMessage = "The data has the following errors:" & vbCrLf & vbCrLf

    If txtDutyManager.Text = "" Then
    sErrorMessage = sErrorMessage & "Duty Manager may not be empty" & vbCrLf
    bErrorOccurred = True
    End If

    If txtOfficeID.Text = "" Then
    sErrorMessage = sErrorMessage & "Office ID may not be empty" & vbCrLf
    bErrorOccurred = True
    End If

    If (Len(txtDutyManager.Text) <> 8) Then
    sErrorMessage = sErrorMessage & "Duty manager must be 8 digits long" & vbCrLf
    bErrorOccurred = True
    Else
    If TPX = "TPX" Then

    End If
    End If

    If (Len(txtOfficeID.Text) <> 4) Then
    sErrorMessage = sErrorMessage & "Office ID must be 4 digits long" & vbCrLf
    bErrorOccurred = True
    End If

    If bErrorOccurred = True Then
    MsgBox(sErrorMessage)
    txtDutyManager.Focus()
    Else
    lblDisplayDutyID.Text = txtDutyManager.Text
    lblDisplayOfficeID.Text = txtOfficeID.Text
    End If

    End Sub

    Now when I try run it it highlights TPX As String = DutyManager.Substring(0, 3)

    And the error is, Object reference not set to an instance of an object.

    ALSO! how to I make it so its not case sensitive? so it will accept tpx, TpX etc?
    I provided the entire code for the sub to hopefully make it easier and clearer. I appreciate all the help so much and thankyou!!
    Last edited by Calvin1991; Apr 16th, 2010 at 07:53 AM.

  15. #15
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: Validating characters in a string

    Take this one

    Code:
    Dim sDutyManager As String
    Dim TPX As String = sDutyManager.Substring(0, 3)
    You are creating one variable and calling the sub string method without assigning value for that variable.

    Take this one

    Code:
    txtOfficeID.Text = ""
    Trim before comparing the values as
    Code:
    txtOfficeID.Text.Trim = ""
    Code:
    vbCrLf
    is from VB

    Code:
    Environment.NewLine
    is the VB.Net Equivalent
    Code:
    If (Len(txtOfficeID.Text) <> 4) Then
    can be
    Code:
    If (txtOfficeID.Text.Trim.Length <> 4) Then
    Last edited by danasegarane; Apr 16th, 2010 at 07:59 AM.
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  16. #16

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Got it going kinda.. but how to I make it so the string isnt case sensitive? Right now it only accepts TPX in caps, not lower case, or case alternations etc.

    If sTPX <> "TPX" Then
    sErrorMessage = sErrorMessage & "Duty Manager must start with TPX" & vbCrLf
    bErrorOccurred = True

    Instead of sTPX <> "TPX" whats the code?

  17. #17
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: Validating characters in a string

    Convert it into Lower case or upper case
    Code:
    If sTPX.ToLower <> "TPX".ToLower Then
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  18. #18
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Validating characters in a string

    Convert all text to upper case when comparing.
    For example:
    Code:
    If (TPX.ToUpper() = "TPX") Then
    ...
    Edit
    Sorry danasegarane, didn't see your reply



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  19. #19
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: Validating characters in a string

    Quote Originally Posted by Optional View Post
    Convert all text to upper case when comparing.
    For example:
    Code:
    If (TPX.ToUpper() = "TPX") Then
    ...
    Edit
    Sorry danasegarane, didn't see your reply
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  20. #20
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: Validating characters in a string

    Code:
    Public Class Form1
    
        'you will need a texbox and label to test this
        'The first 3 characters must be TPX, and the remaining 5 must be a number.
    
        Dim TB1Good As Boolean = False
        Dim i As Integer = 0
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles TextBox1.TextChanged
    
            'check length
            Dim s As String = TextBox1.Text.Trim.ToUpper
            If s.Length <> 8 Then
                TB1Bad("Incorrect Length")
                Exit Sub
            End If
    
            'check start
            If Not s.StartsWith("TPX") Then
                TB1Bad("Must start with TPX")
                Exit Sub
            End If
    
            'at this point, correct length, and starts with TPX
            'check that the remaining 5 are numbers
            If Not Integer.TryParse(s.Substring(3, 5), i) Then
                TB1Bad("Correct format - TPXnnnnn  where n are numbers")
                Exit Sub
            End If
    
            'good data
            TB1Bad("Good") 'for message display
            TB1Good = True
    
            'at this point a flag for good data has been set and i contains the number
        End Sub
    
        Private Sub TB1Bad(ByVal mess As String)
            Label1.Text = mess
            TB1Good = False
        End Sub
    End Class
    Last edited by dbasnett; Apr 16th, 2010 at 08:46 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    That code isnt for Visual Basic Express 2008 is it?

  22. #22
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: Validating characters in a string

    Quote Originally Posted by Calvin1991 View Post
    That code isnt for Visual Basic Express 2008 is it?
    That is what I used to write and test it. Why? Try it. You need a new app with one textbox and one label.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Yeah it works, I'm kinda new to this, so just have to try incorporate it into my code somehow, but thanks

  24. #24
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: Validating characters in a string

    Quote Originally Posted by Calvin1991 View Post
    Yeah it works, I'm kinda new to this, so just have to try incorporate it into my code somehow, but thanks
    It shouldn't be hard. You can get rid of the label business, just there to show you what was going on. The good thing about it though is that the user knows as they are entering whether the input is valid.

    If you have several Texboxes that for example have different start characters, they could all be in the same routine.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Got the TPX bit done, just with the If Not Integer.TryParse(s.Substring(3, 5), i) Then. I need to define i as Integer like you did. But why do I put it equal to zero? I know it works, but just need to be able to explain the code

    EDIT

    If (Len(sDutyManager) <> 8) Then
    sErrorMessage = sErrorMessage & "Duty manager must be 8 digits long" & vbCrLf
    bErrorOccurred = True
    End If
    If Not sDutyManager.StartsWith("TPX") Then
    sErrorMessage = sErrorMessage & "Duty manager must start with TPX" & vbCrLf
    bErrorOccurred = True
    End If
    If Not Integer.TryParse(sDutyManager.Substring(3, 5), i) Then
    sErrorMessage = sErrorMessage & "The last 5 digits of duty manager are not numeric" & vbCrLf
    bErrorOccurred = True
    End If

    Get a crash for the If Not Integer.TryParse(sDutyManager.Substring(3, 5), i), I dont understand why though, havent I already validated the length of the string before trying to use the substring?
    Last edited by Calvin1991; Apr 16th, 2010 at 09:12 AM.

  26. #26
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: Validating characters in a string

    Quote Originally Posted by Calvin1991 View Post
    Got the TPX bit done, just with the If Not Integer.TryParse(s.Substring(3, 5), i) Then. I need to define i as Integer like you did. But why do I put it equal to zero? I know it works, but just need to be able to explain the code

    EDIT

    If (Len(sDutyManager) <> 8) Then
    sErrorMessage = sErrorMessage & "Duty manager must be 8 digits long" & vbCrLf
    bErrorOccurred = True
    End If
    If Not sDutyManager.StartsWith("TPX") Then
    sErrorMessage = sErrorMessage & "Duty manager must start with TPX" & vbCrLf
    bErrorOccurred = True
    End If
    If Not Integer.TryParse(sDutyManager.Substring(3, 5), i) Then
    sErrorMessage = sErrorMessage & "The last 5 digits of duty manager are not numeric" & vbCrLf
    bErrorOccurred = True
    End If

    Get a crash for the If Not Integer.TryParse(sDutyManager.Substring(3, 5), i), I dont understand why though, havent I already validated the length of the string before trying to use the substring?
    First off, lose the Len(). What I posted works and does the same thing.

    Second, the big difference is that I exit sub if the format is incorrect. You aren't.

    Integer(single,double,etc).TryParse checks that a string is a number. If not it returns false and set the variable to 0. If it is a number it returns true and sets the variable to the converted value.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Yeh but if I do
    If txtOfficeID.Text = "" Then
    sErrorMessage = sErrorMessage & "Office ID may not be empty" & vbCrLf
    bErrorOccurred = True
    Exit Sub

    For example, then the message box doesnt come up and nothing happens?

    THANKS a lot for help though appreciate it!

  28. #28
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: Validating characters in a string

    Code:
    Public Class Form1
    
        'you will need a texbox and label to test this
        'The first 3 characters must be TPX, and the remaining 5 must be a number.
    
        Dim TB1Good As Boolean = False
        Dim i As Integer = 0
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles TextBox1.TextChanged
    
            'show all errors at once - though I think it is a bad idea
            Dim isErr As Boolean = False
            'check length
            Dim s As String = TextBox1.Text.Trim.ToUpper
            If s.Length <> 8 Then
                Debug.WriteLine("Incorrect Length")
                isErr = True
            End If
    
            'check start
            If Not s.StartsWith("TPX") Then
                Debug.WriteLine("Must start with TPX")
                isErr = True
            End If
    
            'at this point, correct length, and starts with TPX
            'check that the remaining 5 are numbers
    
            If Not isErr Then
                If Not Integer.TryParse(s.Substring(3, 5), i) Then
                    Debug.WriteLine("Correct format - TPXnnnnn  where n are numbers")
                    isErr = True
                End If
            End If
    
            'good data
            If Not isErr Then
                Debug.WriteLine("Good") 'for message display
                TB1Good = True
                'at this point a flag for good data has been set and i contains the number
            End If
    
        End Sub
    
    End Class
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Yeah, thats better. I know it isnt good showing all the errors in that way but thats only what we've been taught up to so far. I think im going to add your way too with the labels . 1 More question! I have another textbox where the first two characters MUST be capital letters, and can be any letter in the alpha bet. Not too sure about how to ensure they're capital and allow for ANY letter to be entered not just specific ones?

    If txtOfficeID.Text = "" Then
    sErrorMessage = sErrorMessage & "Office ID may not be empty" & vbCrLf
    bErrorOccurred = True
    End If
    If txtOfficeID.Text.Length <> 4 Then
    sErrorMessage = sErrorMessage & "Office ID must be 4 digits long" & vbCrLf
    bErrorOccurred = True
    End If

    I got this so far, just need to add the rest of the damn validation

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    anyone need fast for project plz

  31. #31
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,958

    Re: Validating characters in a string

    Regular expressions...
    vb.net Code:
    1. Dim reg As New Regex("^[A-Z]{2}[a-zA-Z0-9]{4}$")
    2. Dim m As Match = reg.Match(login)
    3. If not m.Success Then
    4.    sErrorMessage = "your message"
    5.    bErrorOccurred = True
    6. End If

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Sorry I cant use Regular Expressions, its for a project for school. Can you give in Visual Basic 2008 code? Would be GREATLY appreciated.

  33. #33
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,958

    Re: Validating characters in a string

    That's need some more work...

    vb.net Code:
    1. If txtOfficeID.Text(0) >= "A"c AndAlso txtOfficeID.Text(0) <= "Z"c Then
    2. 'OK
    3. End If
    4.  
    5. If txtOfficeID.Text(1) >= "A"c AndAlso txtOfficeID.Text(1) <= "Z"c Then
    6. 'OK
    7. End If

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    nvm, got it working thanks

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    76

    Re: Validating characters in a string

    Dim sErrorMessage As String
    Dim bErrorOccurred As Boolean = False
    Dim sDutyManager As String
    Dim i As Integer

    i = 0
    sDutyManager = txtDutyManager.Text.ToUpper
    sErrorMessage = "The data has the following errors:" & vbCrLf & vbCrLf

    If txtDutyManager.Text = "" Then
    sErrorMessage = sErrorMessage & "Duty Manager may not be empty" & vbCrLf
    bErrorOccurred = True
    End If

    If (Len(sDutyManager) <> 8) Then
    sErrorMessage = sErrorMessage & "Duty manager must be 8 digits long" & vbCrLf
    bErrorOccurred = True
    End If

    If Not sDutyManager.StartsWith("TPX") Then
    sErrorMessage = sErrorMessage & "Duty manager must start with TPX" & vbCrLf
    bErrorOccurred = True
    End If

    If bErrorOccurred = False
    If Not Integer.TryParse(sDutyManager.Substring(3, 5), i) Then
    sErrorMessage = sErrorMessage & "The last 5 digits of duty manager not numeric" & vbCrLf
    bErrorOccurred = True
    End If
    End If

    If txtOfficeID.Text = "" Then
    sErrorMessage = sErrorMessage & "Office ID may not be empty" & vbCrLf
    bErrorOccurred = True
    End If

    If (Len(txtOfficeID.Text) <> 4) Then
    sErrorMessage = sErrorMessage & "Office ID must be 4 digits long" & vbCrLf
    bErrorOccurred = True
    End If

    If Not bErrorOccurred Then
    If txtOfficeID.Text(0) >= "A"c AndAlso txtOfficeID.Text(0) <= "Z"c Then

    Else
    sErrorMessage = sErrorMessage & "The first character of Office ID is not a capital letter" & vbCrLf
    bErrorOccurred = True
    End If

    If txtOfficeID.Text(1) >= "A" AndAlso txtOfficeID.Text(1) <= "Z" Then

    Else
    sErrorMessage = sErrorMessage & "The second character of Office ID is not a capital letter" & vbCrLf
    bErrorOccurred = True
    End If
    End If

    If bErrorOccurred = True Then
    MsgBox(sErrorMessage)
    txtDutyManager.Focus()
    Else
    lblDisplayDutyID.Text = txtDutyManager.Text
    lblDisplayOfficeID.Text = txtOfficeID.Text
    End If

    End Sub

    Why is it that the error messages dont appear in message box for the last 5 digits must be numeric, the first letter must be capital, the 2nd letter must be capital? ALl the others appear on the MsgBox popup if I try add details before validating

  36. #36
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: Validating characters in a string

    The correct method(s) for casing were discussed here some time ago. It looks like the whole thread was moved to the CodeBank.

    http://www.vbforums.com/showthread.php?t=555587
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width