Morning All,

I would like to set a limit to a text box so that end user only can enter numbers from 1-32 and not more.

I have setup a validation on keypress to make it only work with numbers i.e digits and nothing else however I am not sure how to set it to only allow 1-32 numbers.

I tried

Dim i as integer

for i=1to32
if textbox2.text>i then
msgbox("not allowed")
end if
next

this however didn't work. I don't think I even wrote it right or not.

Could you please put me to the right direction.

Many thanks

Regards

Jay

try this following code :

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        If Val(TextBox3.Text) > 32 Then
            TextBox3.Text = TextBox3.Text.Remove(0, Len(TextBox3.Text))
            MsgBox("input under 33")
        End If
    End Sub
Comments
Great simple code
cool :)
Just Superb!

Hello

In The Validate Event of textbox Just write

if val(textbox2.text) <1 or   val(textbox2.text)  > 32 then
 msgbox "Not Allowed"
End if

Faisal

Morning All,

I would like to set a limit to a text box so that end user only can enter numbers from 1-32 and not more.

I have setup a validation on keypress to make it only work with numbers i.e digits and nothing else however I am not sure how to set it to only allow 1-32 numbers.

I tried

Dim i as integer

for i=1to32
if textbox2.text>i then
msgbox("not allowed")
end if
next

this however didn't work. I don't think I even wrote it right or not.

Could you please put me to the right direction.

Many thanks

Regards

Jay

Morning All,

I would like to set a limit to a text box so that end user only can enter numbers from 1-32 and not more.

I have setup a validation on keypress to make it only work with numbers i.e digits and nothing else however I am not sure how to set it to only allow 1-32 numbers.

I tried

Dim i as integer

for i=1to32
if textbox2.text>i then
msgbox("not allowed")
end if
next

this however didn't work. I don't think I even wrote it right or not.

Could you please put me to the right direction.

Many thanks

Regards

Jay

Private Sub textbox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus

if cint(textbox1.text) > 1 and cint(textbox1.text) <32 then
msgbox ("not allowed")
else
'do something
end if

End Sub

:)

This question has already been answered. Start a new discussion instead.