By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

How to set up a text box which will only allow positive numbers, Using VB

P: n/a
I need to set up a text box in Visual Basic which will only allow positive numbers and will produce an error message if 1 - A negative number is entered, 2 - something not numeric is entered and 3 - nothing is entered.
Any help will be much appreciated.
Thanks
Jack
Nov 7 '10 #1
Share this Question
Share on Google+
2 Replies


Guido Geurs
Expert 100+
P: 767
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.    If Text1 = "" Then
  3.       MsgBox "Enter a number"
  4.       Exit Sub
  5.    End If
  6.    If Not IsNumeric(Text1) Then
  7.       MsgBox "Enter a NUMBER"
  8.       Exit Sub
  9.    End If
  10.    If Left(Text1, 1) = "-" Then
  11.       MsgBox "enter a POS number"
  12.       Exit Sub
  13.    End If
  14. End Sub
  15.  
Nov 7 '10 #2

P: n/a
If IsNumeric(Text1, intA) true then
If intA > 0 then
..............
Else
MsgBox("Please insert a number greater than 0")
EndIf
Else
MsgBox("Please insert a number")
EndIf
Nov 8 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.