Sorry for the simple question, but..
Anyone point me to an example of how i can validate the contents of a textbox to only allow a percentage, ie 0 to 100.00?
All comments gratefully received unless i fall asleep *smile*
lee
Printable View
Sorry for the simple question, but..
Anyone point me to an example of how i can validate the contents of a textbox to only allow a percentage, ie 0 to 100.00?
All comments gratefully received unless i fall asleep *smile*
lee
This any good?
VB Code:
Private Sub Text1_Validate(Cancel As Boolean) If Val(Text1.Text) < 1 Then MsgBox "Must be at least 1%", vbInformation Cancel = True ElseIf Val(Text1.Text) > 100 Then MsgBox "Can't be more than 100%", vbInformation Cancel = True End If End Sub
Why would you want to validate a percentage to 2 decimal places.
Can;t you just make sure the contents of the test box falls between 0 and 100 instead of 100.00?
Mega.
Try this.
VB Code:
Dim sInput As String sInput = InputBox("Enter a percent:") If IsNumeric(sInput) Then If CSng(sInput) <= 100 And CSng(sInput) >= 0 Then sInput = Format$(sInput, "###.00") End If
What is that : CSng?
converts a number to single
Converts numbers and strings to a single
well if we're going to split hairs...converts an expression to a single data type :)
Well, since we at it.
Converts any string expression or numeric expression to a single. :D