2 Replies - 3428 Views - Last Post: 28 September 2010 - 10:59 AM Rate Topic: -----

#1 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 805
  • Joined: 16-September 09

Identifying Alpha & Numeric Chars

Posted 27 September 2010 - 04:19 PM

Hey guys...I have a simple question here.....

When I want to identify if a string is numeric then I use IsNumeric(String).

Is there anything like this that works with alpha characters? I googled it but I didn't find anything.



If you're wondering why, the reason is, I have a function that removes certain types of characters from a selected string. It works great but I want to add the option to remove all alpha-numerics so this is the obvious place to start before I do all the hard ASCii ID coding.


As always, thanks in advance!!!! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Identifying Alpha & Numeric Chars

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,755
  • Joined: 26-March 09

Re: Identifying Alpha & Numeric Chars

Posted 27 September 2010 - 11:44 PM

I don't believe there is an equivalent "IsAlpha" function.

I would normally do it by checking the ASCII value of each character in a loop.

Alternatively, you could look at using regular expressions, as I think they are good for things like this.

This post has been edited by maj3091: 27 September 2010 - 11:44 PM

Was This Post Helpful? 1
  • +
  • -

#3 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 805
  • Joined: 16-September 09

Re: Identifying Alpha & Numeric Chars

Posted 28 September 2010 - 10:59 AM

Thanks Maj! That's what I was afraid of...however when I was thinking of a way to do this I hadn't considered for/next which made this much easier...in which case I coded it up anyway and it works great. This is what I came up with.


Hope this helps someone else going forward!!

ENUMERATORS -- Just because this makes it look very cool :)
Option Compare Database
Option Explicit

'''''''''ENUMERATORS'''''''''
Enum RemoveType
    RemoveLetters
    RemoveNumbers
    RemoveNonAlphaNumerics
    RemoveAlphaNumerics
End Enum
'''''''''''''''''''''''''''''''''''''''



VARIABLES
Dim StrCnt As Integer
Dim CurChar As String
Dim CurStr As String
Dim ChrASC As Integer
Dim bAlpha As Boolean



FUNCTION
Public Function RemoveCharsFromString(ByRef CurStr As String, RemoveCharType As RemoveType) As String
'THIS IS NOT THE SAME AS THE BUILT IN VB "REPLACE" FUNCTION. THIS IS TO REMOVE MULTIPLE TYPES OF CHARACTERS IN A STRING WITH ONLY ONE FUNCTION.
'Assumes CurStr has been set by the module of form

RemoveCharsFromString = ""
    
'REMOVE LETTERS
If RemoveCharType = RemoveLetters Then
    For StrCnt = 1 To Len(CurStr)
        CurChar = Mid(CurStr, StrCnt, 1)
        If IsNumeric(CurChar) Then RemoveCharsFromString = RemoveCharsFromString & CurChar
    Next StrCnt
    
'REMOVE NUMBERS
ElseIf RemoveCharType = RemoveNumbers Then
    For StrCnt = 1 To Len(CurStr)
        CurChar = Mid(CurStr, StrCnt, 1)
        If Not IsNumeric(CurChar) Then RemoveCharsFromString = RemoveCharsFromString & CurChar
    Next StrCnt
    
'REMOVE ALL ALPHABETIC AND NUMERIC CHARACTERS
ElseIf RemoveCharType = RemoveAlphaNumerics Then
    bAlpha = False
    For StrCnt = 1 To Len(CurStr)
        CurChar = Mid(CurStr, StrCnt, 1)
        If Not IsNumeric(CurChar) Then 'Not numeric
            For ChrASC = 65 To 90
                If UCase(CurChar) = Chr(ChrASC) Then bAlpha = True 'Not alpha
            Next ChrASC
        End If
    Next StrCnt
    If bAlpha = False Then RemoveCharsFromString = RemoveCharsFromString & CurChar
    
'REMOVE ALL NON-ALPHABETIC AND NON-NUMERIC CHARACTERS
ElseIf RemoveCharType = RemoveNonAlphaNumerics Then
    bAlpha = False
    For StrCnt = 1 To Len(CurStr)
        CurChar = Mid(CurStr, StrCnt, 1)
        If IsNumeric(CurChar) Then GoTo SkipFor
        For ChrASC = 65 To 90
            If UCase(CurChar) = Chr(ChrASC) Then GoTo SkipFor  'Check for alphas
        Next ChrASC
SkipFor:
        If bAlpha = False Then RemoveCharsFromString = RemoveCharsFromString & CurChar
    Next StrCnt
End If

End Function



As always, thanks for the input!!!!

This post has been edited by guyfromri: 28 September 2010 - 01:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1