Validations in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adityakommuri
    New Member
    • Feb 2007
    • 1

    Validations in VB

    Can anybody tell me if there is any option to validate data in textbox in tollbox or we have write a code for it..if so plz pass me a sample snippet of code

    Thanks in advance
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. There is no real sample of validation, just an approach.
    Write it out in english
    break it down into the smallest parts you can
    code each part.

    as an example:
    I want this textbox to contain at least 6 characters
    the content of this textbox, excluding any white space, must exceed 5 characters.
    read the content of the textbox
    remove whitespace
    check the length
    if it is greater than 5 carry on
    otherwise keep the focus at this texbox and issue an error messagebox.

    Code:
    Dim stInput As String
    
    stInput = Trim(TextBox1.Text)
    If Len(stInput) < 6 Then
       MsgBox "Input must be 6 characters or more"
       TextBox1.SetFocus
    End If

    Comment

    • lavanyadevi
      New Member
      • Feb 2007
      • 3

      #3
      Originally posted by willakawill
      Hi. There is no real sample of validation, just an approach.
      Write it out in english
      break it down into the smallest parts you can
      code each part.

      as an example:
      I want this textbox to contain at least 6 characters
      the content of this textbox, excluding any white space, must exceed 5 characters.
      read the content of the textbox
      remove whitespace
      check the length
      if it is greater than 5 carry on
      otherwise keep the focus at this texbox and issue an error messagebox.

      Code:
      Dim stInput As String
      
      stInput = Trim(TextBox1.Text)
      If Len(stInput) < 6 Then
         MsgBox "Input must be 6 characters or more"
         TextBox1.SetFocus
      End If
      i f is date(textbx1.te xt) then
      msgbox("your date i s correct")
      else
      msgbox(" pls enter date value only")
      end if

      Comment

      Working...