Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

ISASCII function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Charlie Mac - 25 Feb 2008 20:28 GMT
VBA Gerus,

Is there a function in VBA to derermine if a character is an ASCII
character (A - Z or a - z)?   I need something like this:  msgbox
IsASCII(aWord) returning a one or zero.

Thanks.

Charlie from Texas
Jay Freedman - 26 Feb 2008 02:35 GMT
>VBA Gerus,
>
[quoted text clipped - 5 lines]
>
>Charlie from Texas

To correct a misconception, ASCII (now called ANSI) characters include much more
than A-Z and a-z -- the digits, punctuation, and all other characters in the
range from 0 to 255 are 'ASCII characters'. So I wrote the function name as
IsAlpha instead.

Function IsAlpha(s As String) As Boolean
  Dim retVal As Boolean
  retVal = False
 
  If Len(s) > 0 Then
     If Left$(s, 1) Like "[A-Za-z]" Then
        retVal = True
     End If
  End If
 
  IsAlpha = retVal
End Function

Sub test()
   Dim myText As String
   Dim myChar As String
   Dim msg As String
   Dim i As Long
   
   myText = Selection.Text
   For i = 1 To Len(myText)
       myChar = Mid$(myText, i, 1)
       msg = "'" & myChar & "' is "
       If Not IsAlpha(myChar) Then
           msg = msg & "NOT "
       End If
       msg = msg & "in [A-Za-z]"
       MsgBox msg
   Next
End Sub

As written, this function checks only one character, the first one in the string
passed in as the parameter. If you meant to check a whole word or an entire
string, that would need some slightly different logic.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Charlie Mac - 27 Feb 2008 14:49 GMT
Jay,

Thank you for your reply.  I did not know that the "Like" function
existed.  Your code solved my problem.

Take care,

Charlie from Texas  

>>VBA Gerus,
>>
[quoted text clipped - 45 lines]
>passed in as the parameter. If you meant to check a whole word or an entire
>string, that would need some slightly different logic.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.