Results 1 to 2 of 2

Thread: Illegal Character Comparison

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Is there a faster way to go through a string to detect if there are illegal characters? This is what I am using right now.

    Thank You

    Code:
    Option Explicit
    
    Sub Main()
      'PURPOSE: Test Data
      Dim str_Data As String
      str_Data = "How are you today?"
    
      'PURPOSE: Illegal Characters
      Dim str_IllegalChar As String
      str_IllegalChar = "\/:*?""<>|"
      
      Dim str_Char As String
      Dim int_X As Integer
      For int_X = 1 To Len(str_Data)
        str_Char = Mid(str_Data, int_X, 1)
        If InStr(1, str_IllegalChar, str_Char) <> 0 Then
          MsgBox str_Char
        End If
      Next
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Nope

    I take it you are interested in reporting the illegal
    symbol in which case your code looks as good as anything

    Assuming you have a TextBox for data entry, then:
    If there are loads other illegal chars as well, ones that
    you couldn't type but could paste into your TextBox, then
    you would probably be better checking for legal characters
    since most likely they will be printable.

    Regards
    Paul Lewis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width