|
-
Oct 11th, 2000, 09:16 AM
#1
How can we prevent the user enter some crazy number in text box... i know we can prevent them from non-numeric number... but the user can still enter like "000358" which is not a valid area number or dollar number..... what can i do? they can enter "0.568.254" also..... what should i do?
-
Oct 11th, 2000, 10:17 AM
#2
Member
i've posted this before but i think it's what you are looking for... (taken from vb5 help file on the 'format' command):
MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00") ' Returns "334.90".
MyStr = Format(5, "0.00%") ' Returns "500.00%".
MyStr = Format("HELLO", "<") ' Returns "hello".
MyStr = Format("This is it", ">") ' Returns "THIS IS IT".
hope this helps
-
Oct 11th, 2000, 01:35 PM
#3
Thanks for the hints... i know those also...
But, what i need is prevent the user to enter invalid number, just like Isnumeric can prevent any non-numeric data... but how can we prevent user to enter "03.5"?
-
Oct 11th, 2000, 01:56 PM
#4
_______
<?>
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'no decimals allowed
If KeyAscii = 46 Then KeyAscii = 0
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 11th, 2000, 01:56 PM
#5
Member
ok, try this... it should solve both your worries since it only allows integers.. this works with a textbox named text1 change it to the name of whatever the textbox you are using is and handle the error however you see fit:
Private Sub Text1_LostFocus()
On Error GoTo not_num
Text1.Text = Str(Int(Text1.Text))
Exit Sub
not_num:
MsgBox ("got an error")
End Sub
-
Oct 11th, 2000, 02:03 PM
#6
Thanks for all the suggestion.... and i have tried them before...... (by the way, how can i paste the message icon here?)
The thing is, i allow normal data like 0.21,123, .... but just preventing the crazy number like 02.34, 000000.2 anyone please
-
Oct 11th, 2000, 02:06 PM
#7
Member
what i just sent you does what you asked. as long as they enter the data and click on something else (like an OK button) then it will trigger the lostfocus code in the text box and it works.
-
Oct 11th, 2000, 02:08 PM
#8
Hyperactive Member
Not that hard
Let them enter it. The formatting will take care of it. As for the double decimal points,
if you use IsNumeric(.345.346) it will return false.
Code:
Private Sub Command1_Click()
Dim t As Variant
t = Text1
If IsNumeric(t) Then
t = Format(t, "#,###,###.00")
Debug.Print t
Else
MsgBox("Not a valid number")
End If
Text1.Text = vbNullChar
End Sub
-
Oct 11th, 2000, 02:09 PM
#9
But i try to prevent them entering crazy number but not have a "check" after it... but i think ur's is best by now Again, how can i have the message icon in the message?
-
Oct 11th, 2000, 02:11 PM
#10
_______
<?>
If you have a specify context to what you want to enter then you should use a MaskeditBox and not a text box.
If..if you entry is always 3 numbers a comma 3 numbers a decial and 2 numbers.
The maskeditbox mask would be:
MaskEdBox1.Mask = "###,###.00"
That way a user must enter number number number comma
number number number decimal number number
If not sure how to use one then add one to your form, select it and press F1
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 11th, 2000, 02:12 PM
#11
dsy5, if i do what you said, what would be the number after this 00000.5? will it returns 0.5 or "invalid number"? thanks again
-
Oct 11th, 2000, 02:20 PM
#12
Hyperactive Member
It would return .50.
Clip the code and try it.
Need a Textbox named text1 (default) and a command button named Command1 (default).
-
Oct 11th, 2000, 02:22 PM
#13
HeSaidJoe, thanks for the reply.....
but i can not use the masked nox, i thought that before... because i ask people to enter the cost they spend on clothes... it can be 0.000003 to 1000000000000 some crazy people enters 0542.32 make me crazy
-
Oct 11th, 2000, 02:23 PM
#14
Member
if i understand what you are saying, you could make a label and have it display an error when there is one instead of having a msgbox pop up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|