by Matthew Roberts (26 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
Simple function to validate string contents. Compares a given string to a list of illegal values and evaluates whether or not it contains any. Very fast and easy. Can also be used as a string search function with a little modification.
Inputs
strSource - String you are checking
strCompare - String of illegal characters
Assumes
To run:
If Match (strMyFile, "~!@#$%^&*()+`{}[]?><,/") Then
MsgBox "File contains illegal characters!", vbExclaimation
End If
.
Code Returns
Boolean - True = Source string contains an illegal character.
Public Function Match(strSource As String, strCompare As String) As Boolean
Dim lngCheck As Long
For lngCheck = 1 To Len(strCompare)
If InStr(strSource, Mid(strCompare, lngCheck, 1)) Then
Match = True
Exit Function
End If
Next lngCheck
End Function