Input box

Caliboy_2005
08-11-2005, 06:26 PM
Hi,

Is there any code that I can use so that a user can not input characters in input box, it'll accept numbers only????

Thanks

mrjeffy321
08-11-2005, 07:26 PM
I dont think you can restrict the user from inputting certain characters into the standard Input box, your best bet would be to either check to see if the input is valif, if not then promp again, or you could design your own input box with another form that you could restrict the user's input.

Caliboy_2005
08-11-2005, 07:57 PM
I am pretty sure that there is a way, because I experienced it before. I just forgot how.

LaVolpe
08-11-2005, 08:08 PM
Nope, the only way I know of is to subclass the input box. Much easier to create your own little popup, modal or non-modal, window with a textbox on it that you control 100%.

jlm
08-11-2005, 10:57 PM
I gave ita quick shot with isnumeric(inputbox ("blah")) but no luck. from waht I can tell, if you simply must have an input box instead of creating a new input form, then this is how you will need to do it. Ofcourse the msgboxes are not needed. if u get rid of them, it will simply force the inputbox in the users face until only numerics are entered. then it will accept it and store the data in MyVariable.

If you do decide to make your own form, simply put this in the forms code window:
assuming your text box is named text1...

private sub text1_change()
if isnumeric(text1) then
exit sub
else
text1.text = vbnull ' or you could just tell it text1.text = ""
end if
end sub

for ultimate laziness I suggest the following:

Dim MyVariable As String
Restart_Popup:
MyVariable = InputBox("Blahhhhhh", "Please enter Numerics only!")
If IsNumeric(MyVariable) Then
MsgBox "Yay its numerics only!"
Else
MsgBox "Numerics only!!!"
GoTo Restart_Popup
End If

Cyroxis
08-11-2005, 11:51 PM
for ultimate laziness I suggest the following:

Dim MyVariable As String
Restart_Popup:
MyVariable = InputBox("Blahhhhhh", "Please enter Numerics only!")
If IsNumeric(MyVariable) Then
MsgBox "Yay its numerics only!"
Else
MsgBox "Numerics only!!!"
GoTo Restart_Popup
End If


Ugh.... That is some questionable code. It uses the debated goto...I personal would so something like this.

Do
MyVariable = InputBox("Blahhhhhh", "Please enter Numerics only!")
Loop while IsNumeric(MyVariable)
MsgBox "Yay its numerics only!"

TeraBlight
08-12-2005, 12:29 AM
jlm, please use indentation in your code samples. You are free do write your own code however you like, but any recommendations you make to others should follow commonly accepted coding standards :)

RoofRabbit
08-12-2005, 05:17 PM
I'd just create a form, make it look like the input box I want to see and limit it's textbox (for inputing text) accept digits only. If you do it this way, why not pretty up the dialog a little while you're at it or make it more specific to it's particular purpose.

Iceplug
08-12-2005, 07:46 PM
In order to restrict a regular textbox from accepting numbers, you must intercept the keyascii wthin the keypress event and set it to 0 if it is not a number (48-57), backspace (9), or decimal (46), or delete (122, optional).

wakjah
08-12-2005, 07:50 PM
Or use the masked edit box.

Caliboy_2005
08-12-2005, 09:56 PM
Yes, I think that would be a great idea, to have a form and then and a textbox, and then restrict to numbers only as input.

Thanks

TeraBlight
08-12-2005, 10:17 PM
a number (48-57), backspace (9), or decimal (46), or delete (122, optional).
People always forget about the minus sign (45)... discrimination against negative numbers, that's what that is! ;)

Caliboy_2005
08-13-2005, 01:09 PM
Also, I need the DOT (".") in my case....

Iceplug
08-13-2005, 02:49 PM
Also, I need the DOT (".") in my case....
That would be the *ahem* decimal.
decimal (46)
In order to restrict a regular textbox from accepting numbers
That's supposed to read "In order to restrict a regular textbox to only accept numbers". :o
People always forget about the minus sign (45)... discrimination against negative numbers, that's what that is!
Sorry, minus sign 45, plus sign 43, and if you want the comma, that is 44. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum