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

how to dellete posts? i Understood wrong and put wrong answear

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
commented: Just Superb! +1
commented: cool :) +1
commented: Great simple code +1

Wow!! that worked like a magic!!

Superb!

Many thanks

Regards

J

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

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.