Code Snippets

  

Visual Basic Source Code



Check all textboxes in form if they contain numbers only

check if all the textboxes in a form contain numbers only. not needed textboxes to be in array

Submitted By: raziel_
Actions:
Rating:
Views: 3,025

Language: Visual Basic

Last Modified: April 7, 2010

Snippet


  1. Public Function Chk_If_Numeric(ByRef frm As Form) As Boolean
  2. 'the function check from the textboxes in a certain form'
  3. Dim cControl As Control
  4.  
  5. Chk_If_Numeric = True  'set the variable to default value'
  6.     For Each cControl In frm 'looping trough the form controls'
  7.         If TypeOf cControl Is TextBox Then 'finding only textboxes'
  8.             If Not IsNumeric(cControl.Text) Then 'check if contain only numbers'
  9.                 Chk_If_Numeric = False 'if one of them is not we return false'
  10.             End If
  11.         End If
  12.     Next
  13. End Function
  14.  
  15. Private Sub Command1_Click()
  16. 'a test button click '
  17.     If Chk_If_Numeric(Form1) Then
  18.         MsgBox "all numbers"
  19.     Else
  20.         MsgBox "not all are numeric"
  21.     End If
  22. End Sub
  23.  

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.