Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Help with textbox Function

okay, here is my problem-
i want to check if the textbox is 9 digit long and isnumeric- once its check then i can save, but if not it highlights and set focus, i got it right doing it the regular way, but once i write my function it does not work. im not sure what i did wrong. here is what i got

Public Function save(ByVal textbox As TextBox) As TextBox

If Not IsNumeric(textbox) Or Not textbox.Text.Length = 9 Then
MsgBox("can not be save")
textbox.BackColor = Color.red
textbox.SelectAll()
textbox.Focus()
ElseIf IsNumeric(textbox) And textbox.Text.Length = 9 Then
MsgBox("phone must be 10 digits")

End If

Return textbox

End Function

when i call it in my save button it wont work, it keep sayin can not be save even if i typed 123456789.
[925 byte] By [gizmo12345] at [2007-11-11 10:30:15]
# 1 Re: Help with textbox Function
okay, here is my problem-
i want to check if the textbox is 9 digit long and isnumeric- once its check then i can save, but if not it highlights and set focus, i got it right doing it the regular way, but once i write my function it does not work. im not sure what i did wrong. here is what i got

Public Function save(ByVal textbox As TextBox) As TextBox

If Not IsNumeric(textbox) Or Not textbox.Text.Length = 9 Then
MsgBox("can not be save")
textbox.BackColor = Color.red
textbox.SelectAll()
textbox.Focus()
ElseIf IsNumeric(textbox) And textbox.Text.Length = 9 Then
MsgBox("phone must be 10 digits")

End If

Return textbox

End Function

when i call it in my save button it wont work, it keep sayin can not be save even if i typed 123456789.It doesn't work because you are testing whether the textbox object is numeric not the text in the textbox. When you call IsNumeric you should pass textbox.text in both cases.
TwoFaced at 2007-11-11 20:47:31 >