Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check String if it has an ascii like "/" and ":" using VBA

Tags:

vba

Here's my code but i want to know how will I know if the string has special characters like '/' or ':'.Many Thanks. Much great if you can edit my function.

Do Until EOF(1)
   Line Input #1, LineFromFile <-----LineFromFile is the string
     If HasCharacter(LineFromFile) = True Then
        MsgBox "This File should be uploaded to FilePath2"
      Else
     Blah Blah Blah.......

This is my function

Function HasCharacter(strData As String) As Boolean
   Dim iCounter As Integer

   For iCounter = 1 To Len(strData)
     If ....(Don't know what to say) Then
       HasCharacter = True
       Exit Function
     End If
   Next iCounter
End Function
like image 749
Roi patrick Florentino Avatar asked Jan 11 '23 14:01

Roi patrick Florentino


1 Answers

Change your code to this:

Function HasCharacter(strData As String) As Boolean

     If InStr(strData, "/") > 0 Or InStr(strData, ":") > 0 Then
       HasCharacter = True
     Else
       HasCharacter = False
     End If
End Function

The function InStr returns the position of the string if found, else it returns 0.

like image 65
Manuel Allenspach Avatar answered Jan 13 '23 03:01

Manuel Allenspach