943,545 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1795
  • VB.NET RSS
Jun 19th, 2008
0

Limit Textbox to 32

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaytheguru is offline Offline
18 posts
since Aug 2007
Jun 19th, 2008
0

Re: Limit Textbox to 32

how to dellete posts? i Understood wrong and put wrong answear
Last edited by Dajak; Jun 19th, 2008 at 9:20 am. Reason: Understodd wrong posted comment that doesent helped
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Dajak is offline Offline
8 posts
since Jun 2008
Jun 19th, 2008
3

Re: Limit Textbox to 32

try this following code :
vb Syntax (Toggle Plain Text)
  1. Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
  2. If Val(TextBox3.Text) > 32 Then
  3. TextBox3.Text = TextBox3.Text.Remove(0, Len(TextBox3.Text))
  4. MsgBox("input under 33")
  5. End If
  6. End Sub
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,135 posts
since Nov 2007
Jun 19th, 2008
0

Re: Limit Textbox to 32

Wow!! that worked like a magic!!

Superb!

Many thanks

Regards

J
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaytheguru is offline Offline
18 posts
since Aug 2007
Jun 19th, 2008
0

Re: Limit Textbox to 32

Hello

In The Validate Event of textbox Just write

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. if val(textbox2.text) <1 or val(textbox2.text) > 32 then
  3. msgbox "Not Allowed"
  4. End if

Faisal


Click to Expand / Collapse  Quote originally posted by jaytheguru ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mafaisal is offline Offline
11 posts
since Apr 2008
Jun 27th, 2008
0

Re: Limit Textbox to 32

Click to Expand / Collapse  Quote originally posted by jaytheguru ...
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

Last edited by naz82; Jun 27th, 2008 at 10:39 am.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
naz82 is offline Offline
13 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Form buttons problem.
Next Thread in VB.NET Forum Timeline: Using the combo box to set the Default Member and Value Member names





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC