We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,344 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Range of numbers in textboxes

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...

5
Contributors
4
Replies
8 Hours
Discussion Span
2 Months Ago
Last Updated
21
Views
masterfact18
Light Poster
43 posts since Jan 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

its simple
use the following code on textbox lostfocus event

If Val(Text1.Text) > 100 Then
MsgBox "Invalid "
Text1.SetFocus
End If
rishif2
Junior Poster
156 posts since Dec 2012
Reputation Points: 54
Solved Threads: 32
Skill Endorsements: 3

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

QVeen72
Veteran Poster
1,017 posts since Nov 2006
Reputation Points: 118
Solved Threads: 164
Skill Endorsements: 5

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

cxzei
Newbie Poster
4 posts since Sep 2008
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

tinstaafl
Nearly a Posting Virtuoso
1,334 posts since Jun 2010
Reputation Points: 355
Solved Threads: 234
Skill Endorsements: 14

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0843 seconds using 2.73MB