use the built in isNumeric function to check the string and if the return is true then perform the needed steps A language that doesn't affect the way you think about programming is not worth knowing.
You can use the API function: IsCharAlpha.
Drop this in a public module
Option Explicit
Private Declare Function IsCharAlpha Lib "user32" Alias "IsCharAlphaA" (ByVal cChar As Byte) As Long
Public Function IsAlphaA_pFb(ByVal sChar As String) As Boolean
Dim lChar As Long
lChar = Asc(sChar)
IsAlphaA_pFb = IsCharAlpha(lChar)
End Function
Public Function IsAlphaB_pFb(ByVal AsciiChar As Byte) As Boolean
IsAlphaB_pFb = IsCharAlpha(AsciiChar)
End Function
This gives you two different ways of passing the char:
The one way is to pass a literal character.
The other way is to pass an ASCII character code (such as when passing the character code from a KeyDown or KeyPress event)
There is another API function to check for AlphaNumeric (IsCharAlphaNumeric). And, between the two you can create a function to check just for numbers. Numbers in the sense of a single digit - no decimals:
If the IsCharAlphaNumeric returns TRUE and the IsCharAlpha returns FALSE, then the char is a number.
So, in a Key press event that should allow only numbers, you can check if the char is a negative sign, or a decimal separater first, and if not then pass the code to your IsAlphaNumeric function and it will determine if the char is a number. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.