473,548 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use IsCharAlphaNume ric() Rather Than ASCII Values

ADezii
8,834 Recognized Expert Expert
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(chara cter)) to the ANSI values for the ranges. The Windows API, however, provides a Function designed specifically for this purpose IsCharAlphaNume ric(). IsCharAlphaNume ric() 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.
  1. Slow version of the code:

    Expand|Select|Wrap|Line Numbers
    1.  strTestChar As String, intTestChar As Integer
    2. Const conFirstChar = 65
    3. Const conLastChar = 90
    4. Const conFirstDigit = 48
    5. Const conLastDigit = 57
    6.  
    7. strTestChar = "4"
    8. intTestChar = Asc(UCase(strTestChar))
    9.  
    10. If (intTestChar >= conFirstChar And intTestChar <= conLastChar) Or _
    11. (intTestChar >= conFirstDigit And intTestChar <= conLastDigit) Then
    12. 'the character is AlphaNumeric
    13. Else
    14. 'the character is Not AlphaNumeric
    15. End If
  2. Faster and more efficient version of the code:

    Expand|Select|Wrap|Line Numbers
    1.  Private Declare Function IsCharAlphaNumeric Lib "User32" Alias "IsCharAlphaNumericA" (ByVal cChar As Byte) As Long
    2. Private Declare Function IsCharAlpha Lib "User32" Alias "IsCharAlphaA" (ByVal cChar As Byte) As Long
    Expand|Select|Wrap|Line Numbers
    1. IsCharAlphaNumeric(Asc(strTestChar)) Then
    2. 'the character is AlphaNumeric
    3. Else
    4. 'the character is Not AlphaNumeric
    5. End If
    6.  
    7. 'Similiar Function to test for Alphas
    8. If IsCharAlpha(Asc(strTestChar)) Then
    9. 'the character is an Alpha
    10. Else
    11. 'the character is Not an Alpha
    12. End If
  3. 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.
Jun 17 '07 #1
2 9643
Chris Austin
1 New Member
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.
Dec 11 '07 #2
ADezii
8,834 Recognized Expert Expert
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.
Dec 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6812
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 of each character? Thanks, Drew
1
2989
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 to do is when characters are entered the function will loop through the entered values and throw an alert for each of the corresponding ASCII...
1
4222
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 of text was pasted in, and then grab the ascii value(s) that are > 128?: <script type="text/javascript"> function toASCII(s) {
7
4024
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. However, at the moment I am just getting more gibberish so I'm probably doing something wrong. I tried using ASCII Encoding before to get the ASCII...
1
4164
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 string values. thanks in advance
1
1515
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 someone help me on this? Thanks.
0
3147
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 port class in C# is accepting only ASCII values upto 127 only, the values those greater than 127 ,is automatically converted to value 63(?) ,ihave...
10
6048
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 basically, I want to make a big matrix of values in an array. I know this can be done using a hex editor, but in C++ I'm not sure how to get the...
0
1364
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 values as bellow i want to change this code and whtever i m doing my values is coming wrong coz i want both integer as well as decimal point ascii...
5
4643
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 button1_Click(object sender, EventArgs e) { int b = new int; StreamReader sw = new StreamReader("c: \\28D.09N"); for...
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.