There are 2 things you can do.
1) Check if it's <0
-
valid = CInt(txtBox.text)
-
if valid <> 0 then
-
2) (more advanced) do not allow the "-" character to be entered. In the txtBox_KeyPress() sub routine, one of the values passed in is the key that was pressed. Check if it is the ASCII value of "-" (I don't have it memorized but I'm sure my buddy 'Google' can help you) and if ascii <> # you're good. If it is, display " " in the textbox instead (ascii 1 or 2 I think).
Hope this helps
- LB
PS do a Google search for 'Extended ASCII Chart'. You'll get millions of hits
Unfortunately the first one does not work for negative numbers
You can either fail at a negative or convert to a positive.
'check for negative or 0
valid = CInt(TextBox.Text)
If valid <= 0 Then Exit Sub 'or something else
OR
'convert to positive and check for 0
valid = Abs(CInt(TextBox.Text))
If valid = 0 Then Exit Sub 'or something else