View Single Post
Old Nov 21, 2008, 09:08 AM   #14
GT08
5 Posts
 
Join Date: Nov 2008
Posts: 18 (0.01/day)
Thanks: 7
Thanked 0 Times in 0 Posts

Quote:
Originally Posted by FordGT90Concept View Post

And let me give you a tip to cut down on the repetitiveness of your code. You can write a sub like this to perform all those checks:

Code:
Private Function Validate(ByRef obj As TextBox) As Double
  If (obj.Text.Length > 0) Then
    Dim value As Double = Convert.ToDouble(obj.Text)
    If (value.Text  > 10) Then
      obj.BackColor = Color.Pink
      MsgBox("Value must be between 1 and 10.")
    Else
      obj.BackColor = Color.White
      Return value
    End If
  End If
End Function
Then to validate a control, you'd just have to do the following:
Code:
Validate(txtbox1)
You can play with that concept to make it how you like it. It cuts way down on the repetition.

Where would I put this code? Would it be in my form load or my txtbox1 or in my button (process order)?

As it says " 'Return' Statement in a sub or a set cannot return a value"
GT08 is offline  
Reply With Quote