PlanetSquires Forums

Support Forums => General Board => Topic started by: Paul Squires on August 19, 2015, 01:41:54 PM

Title: FF_VERIFY
Post by: Paul Squires on August 19, 2015, 01:41:54 PM



''
''  FF_VERIFY
''  Determine whether each character of a string is present in another string.
''
''  Returns zero if each character in MainString is present in MatchPattern.
''  If not, it returns the position of the first non-matching character in MainString.
''  This function is very useful for determining if a string contains only numeric
''  digits, for example.
''  This function is case-sensitive.
''  If nStart evaluates to a position outside of the string, or if nStart is zero,
''  then the function returns zero.
''
Function FF_Verify( ByRef nStart        As Integer, _
                    ByRef sMainString   As String, _
                    ByRef sMatchPattern As String _
                    ) As Integer

   Dim nLenMain As Integer = Len(sMainString)
   Dim nPos     As Integer = 0   ' position of first non-match
   Dim i        As Integer
   Dim y        As Integer
   
   If (nStart <= 0) Or (nStart > Len(sMainString)) Then Return 0
   
   ' Get each character in sMainString and look for it in sMatchPattern
   ' Using string pointer indexing for speed.
   nStart = nStart - 1   ' convert to zero based
   For y = nStart To nLenMain - 1
      i = Instr( sMatchPattern, Chr(sMainString[y]) )
      If i = 0 Then nPos = y: Exit For
   Next
   
   Function =  nPos + 1  ' convert back to one based
   
End Function