Limit Textbox to 32

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2007
Posts: 16
Reputation: jaytheguru is an unknown quantity at this point 
Solved Threads: 0
jaytheguru jaytheguru is offline Offline
Newbie Poster

Limit Textbox to 32

 
0
  #1
Jun 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 8
Reputation: Dajak is an unknown quantity at this point 
Solved Threads: 1
Dajak Dajak is offline Offline
Newbie Poster

Re: Limit Textbox to 32

 
0
  #2
Jun 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Limit Textbox to 32

 
3
  #3
Jun 19th, 2008
try this following code :
  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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 16
Reputation: jaytheguru is an unknown quantity at this point 
Solved Threads: 0
jaytheguru jaytheguru is offline Offline
Newbie Poster

Re: Limit Textbox to 32

 
0
  #4
Jun 19th, 2008
Wow!! that worked like a magic!!

Superb!

Many thanks

Regards

J
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 11
Reputation: mafaisal is an unknown quantity at this point 
Solved Threads: 0
mafaisal mafaisal is offline Offline
Newbie Poster

Re: Limit Textbox to 32

 
0
  #5
Jun 19th, 2008
Hello

In The Validate Event of textbox Just write

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

Faisal


Originally Posted by jaytheguru View 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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 13
Reputation: naz82 is an unknown quantity at this point 
Solved Threads: 1
naz82's Avatar
naz82 naz82 is offline Offline
Newbie Poster

Re: Limit Textbox to 32

 
0
  #6
Jun 27th, 2008
Originally Posted by jaytheguru View 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






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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC