Results 1 to 2 of 2

Thread: New to VB6

  1. #1
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    19

    Wink Unanswered: New to VB6

    Hi,

    I'm very new to VB6. I'm trying to figure out a way to validate first name and last name fields, allowing for special characters such as - and '.

    Can anyone offer me some solutions?

    Thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Posts
    3

    Re: New to VB6

    Originally posted by bbk
    Hi,

    I'm very new to VB6. I'm trying to figure out a way to validate first name and last name fields, allowing for special characters such as - and '.

    Can anyone offer me some solutions?

    Thanks in advance.

    I assume you are wanting to validate the data entered by the user before adding it to the database (or whatever use). The following code will work, probably not the most efficient way, but it works.

    'Assume textbox named Text1

    Private Sub Text1_Change()

    Dim a As String

    If Text1 = "" Then Exit Sub

    a = Right$(Text1, 1)

    If ((a > Chr(64) And a < Chr(91)) Or (a > Chr(96) And a < Chr(123)) _
    Or (a = Chr(45)) Or (a = Chr(39))) Then

    Text1 = Text1

    Else

    Text1 = IIf(Len(Text1) > 1, Left$(Text1, Len(Text1) - 1), "")

    End If

    Text1.SelStart = Len(Text1)

    End Sub

    This checks on each letter typed. You could also use the LostFocus event and loop through the entire length of the string checking each character.

    Hope this points you in a right direction.

Posting Permissions

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