Many times we need to determine if a particular character, whether alone, or among other characters in a String, is an AlphaNumeric character (if it falls in the range of characters from A - Z, or a to z, or 0 - 9). The traditional method of doing this in VBA is to compare the Asc(UCase(character)) to the ANSI values for the ranges. The Windows API, however, provides a Function designed specifically for this purpose IsCharAlphaNumeric(). IsCharAlphaNumeric() is significantly faster than its counterpart. You simply pass the ASCII value of the character as an Argument to this Function and it returns True if the character is AlphaNumeric and False if it is not. Both the slow and faster versions of the code will be illustrated below. Be sure to Declare the API Function(s) in the Declarations Section of a Module. - Slow version of the code:
- strTestChar As String, intTestChar As Integer
-
Const conFirstChar = 65
-
Const conLastChar = 90
-
Const conFirstDigit = 48
-
Const conLastDigit = 57
-
-
strTestChar = "4"
-
intTestChar = Asc(UCase(strTestChar))
-
-
If (intTestChar >= conFirstChar And intTestChar <= conLastChar) Or _
-
(intTestChar >= conFirstDigit And intTestChar <= conLastDigit) Then
-
'the character is AlphaNumeric
-
Else
-
'the character is Not AlphaNumeric
-
End If
- Faster and more efficient version of the code:
- Private Declare Function IsCharAlphaNumeric Lib "User32" Alias "IsCharAlphaNumericA" (ByVal cChar As Byte) As Long
-
Private Declare Function IsCharAlpha Lib "User32" Alias "IsCharAlphaA" (ByVal cChar As Byte) As Long
- IsCharAlphaNumeric(Asc(strTestChar)) Then
-
'the character is AlphaNumeric
-
Else
-
'the character is Not AlphaNumeric
-
End If
-
-
'Similiar Function to test for Alphas
-
If IsCharAlpha(Asc(strTestChar)) Then
-
'the character is an Alpha
-
Else
-
'the character is Not an Alpha
-
End If
- NOTE: There is also a similar API Function (IsCharAlpha()) that checks a character to see whether itis an Alpha (a - z or A - Z). Its code and Declaration is also listed.
2 9628
I'm trying this out. The business need is having to filter out records containing fields where non alphanumeric (@, ., !) characters are contained within one of its fields. The remaining records are those which have to be researched. Eliminating the non-pertinent records using automation will save approx. 20 minutes each time this audit is performed. Thanks!
I'll try to report back to the thread on whether or not this application of the method was successfull.
I'm trying this out. The business need is having to filter out records containing fields where non alphanumeric (@, ., !) characters are contained within one of its fields. The remaining records are those which have to be researched. Eliminating the non-pertinent records using automation will save approx. 20 minutes each time this audit is performed. Thanks!
I'll try to report back to the thread on whether or not this application of the method was successfull.
Hope this works out for you, it is the most efficient Method for establishing whether or not a character is AlphaNumeric.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Drew |
last post by:
I need to display the ASCII numeric values of each letter in a string.
I think strings are stored in unicode in C# (?)
I can convert the string to a char array but how do I get the ascii values...
|
by: Kermit Piper |
last post by:
Hello,
I have a function that lets me convert one character and throw an alert
with the corresponding ASCII value, but what I am having trouble with
is applying it to a text box. What I'm trying...
|
by: Kermit Piper |
last post by:
Hello,
OK, almost there. Here's what I have so far, which handles characters
as they're typed in. Could someone please show me how I would loop
through all the values that are entered if a block...
|
by: Jeffrey Spoon |
last post by:
Hello, I'm a bit stuck trying to convert a text file which contains
extended ASCII text and changing the ASCII values so they become
readable. I do this by subtracting 127 from the ASCII value....
|
by: adnanahmed714 |
last post by:
hi all
i have a string
<cr><lf>999,1.52,32.85,5.91,15.81,1.39,26.17,15.75,12.3
want to calculate its ASCII values sum which is equal to 2411.How can i calculate ascii sum of all the...
|
by: Bangaru |
last post by:
Hi,
How do SQL 2005 handle Non-ASCII values?
My application is in VB 6 and SQL server 2005, and when I import non-ascii values like pound symbol, it is converted to question mark...
Can...
|
by: nmsreddi |
last post by:
Hi friends
I am working on serialport in c# ,i am using C#2005 i have successfully done the serial communication with GSM modem and able to send and receive data ,
the main problem ,the serial...
|
by: manontheedge |
last post by:
I want to read in an image file ( bmp, jpeg, ... ) so I can retain it's ascii / binary values, and alter the image. How can I do this in C++ ( I'm using Visual Studio, various versions ).
so...
|
by: squrel |
last post by:
Hello All,
I have a table in my database with a field itemqty and the type was int and need to change it to decimal as i need the decimal point in my textbox.. i have a code for integer ascii...
|
by: siddhanta |
last post by:
hi,
i read the ascii value from a file and wrote the decimal one in other file.
But values above "127" i.e. extended ascii are printed as" 65533."
here ais wat i did:
private void...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |