To allow a space in front of after the number you can modify the check If Is Numeric(Trim(Text Box82)) = true Then However, I often like to apply both preventive and corrective measures when I validate data.
By preventive, I mean show the format or show default values.
to revalidate if its whole number then he can use abs() i guess Dim x As Integer x = Input Box("Enter integer") If x = Int(x) Then Msg Box "integer" Else Msg Box "not integer" End If I'm just not sure if he means the vb integer (can have decimals), or the mathematical integer (no decimals) so thats all Im saying.
Also I have day and month input limited to 2 characters and year to 4.
It works fine with numbers from 10 to 31 and it properly puts an warning message when input is 0 or 32 and on. When I put in numbers from 4 to 9 it puts on a warning message, as I figured out later that program considers empty space after one character input as 0.
But this makes the structure of the code a little more complex than you might anticipate: ' Form-level variables Dim save Text As String Dim save Sel Start As Long Private Sub Text1_Got Focus() ' Save values when the control gets the focus. Static nested Call As Boolean If nested Call Then Exit Sub ' Test the control's value here. You should be aware that this function isn't robust enough for most real-world applications.
For example, the Is Numeric function incorrectly considers these strings as valid numbers: 123,,,123 345- 34 ' What if it isn't a currency field?
Just for curiosity if someone types a space before typing the number or a space after how do you treat that?
To allow a space in front of after the number you can modify the check If Is Numeric(Trim(Text Box82)) = true Then" id="ctl00_m_m_i_ctl00_gr_ctl01_bestanswerbody" class="textarea-bestanswerhidden" name="bestanswerbody" answerbody Id="3947196" / This If (Is Numeric(Text Box82) = true) Then will check if the textbox has a numeric value or not.
Crouchie, Although I use forever Messagebox, is your statement not true, Msg Box versus Message Box. NET, the Msg Box method is a Visual Basic Runtime wrapper around a call to the Message Box. You can also use CType to convert a Msg Box Result to a Dialog Result.
Note Msg Box returns the same integer values returned by Message Box. The values in these enumerations have the same meanings: OK = 1, Yes = 6, No = 7, and so on.
What you really need is a bullet-proof method to trap invalid values. Sel Start = save Sel Start End If End Sub Private Sub Text1_Key Up(Key Code As Integer, Shift As Integer) save Sel Start = Text1.
Before I offer you a decent solution to the problem, let me explain why you can't rely solely on trapping invalid keys for your validation chores. Sel Start End Sub Private Sub Text1_Mouse Down(Button As Integer, _ Shift As Integer, X As Single, Y As Single) save Sel Start = Text1.
What if the user pastes an invalid value from the clipboard? Sel Start End Sub Private Sub Text1_Mouse Move(Button As Integer, _ Shift As Integer, X As Single, Y As Single) save Sel Start = Text1.