place textbox input handling code in a function?

swu

Active member
Joined
Mar 26, 2005
Messages
33
Programming Experience
1-3
Could someone give me some direction/post a sample of how to handle user interaction with textboxes without having to cut and paste code for each text box?

Basically I would like to create a few functions to handle testing and formatting of text box input by the user.

I have the code for each textbox working isnumeric, format, etc . . . I'm having problems setting up the funtion where it can be applied to a text box on my forms through a function.

thanks in advance.
 
You mean something like...

VB.NET:
Private Function ValidateTextbox(byval Str as String) As Boolean
'Validation here
Return True or False
End Function


Then call it, and supply it with the text you want to validate


VB.NET:
Dim ContinueProgram As Boolean = False
 
ContinueProgram = ValidateTextbox(SomeTextbox.Text)
 
If Not ContinueProgram then
 
MessageBox.Show("'" & SomeTextBox.Text + "' Is Not Valid, Please Enter Only Numerical Data")
 
thanks

Thanks vis . . . that will work

The method I was looking at was passing the textbox object to the function, but yours will work just as well.

I was having an issue passing a textbox object to a function.

my code was something like

Private Function nput(Tbox As TextBox)
Dim Tbox As TextBox
Dim tbtxt As String
tbtxt = Tbox.Text
MsgBox (tbtxt)
End Function

Thank you for your assistance
 
you wouldnt do this line in red, as it is a re-statement of the line in green:


Private Function nput(Tbox As TextBox)
Dim Tbox As TextBox
Dim tbtxt As String
tbtxt = Tbox.Text
MsgBox (tbtxt)
End Function
 
Back
Top