1,105,578 Community Members

Range of numbers in textboxes

Member Avatar
masterfact18
Light Poster
43 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

what i want is to put a range in the textboxes like 1-100 and will not accept if it is greater than 100
or a negative number...

hoping for your response...

Member Avatar
rishif2
Posting Whiz in Training
284 posts since Dec 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 4 [?]
 
0
 

its simple
use the following code on textbox lostfocus event

If Val(Text1.Text) > 100 Then
MsgBox "Invalid "
Text1.SetFocus
End If
Member Avatar
QVeen72
Veteran Poster
1,016 posts since Nov 2006
Reputation Points: 104 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 7 [?]
 
0
 

Hi,

In Property pages of Text1 .. MaxLength = 3
write this code, in Validate Event of textbox

Private Sub Text1_Validate(Cancel As Boolean)
    If Val(Text1.Text) > 0 And Val(Text1.Text) <=100 Then
    Else
        Cancel = True
    End If
End Sub

Regards
Veena

Member Avatar
cxzei
Light Poster
28 posts since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

If you just want the number entered...use a NumericUpDown control, it will allow you to set a valid range of values

Member Avatar
tinstaafl
Postaholic
2,014 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 403 [?]
Skill Endorsements: 36 [?]
 
0
 

A MaskedEdit Control will restrict your input to numbers and you can specify a certain number of digits, and you can specify formatting as well.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: