|
-
Apr 2nd, 2000, 11:02 PM
#1
Thread Starter
Member
Is there a method for finding characters in strings?
What I need is a method or function that will return an array that contains a list of the positions of the characters in the string. Here is the code that I have written so far. This code exists in a module and is referenced by several forms. As of right now, when I hit play, my form gives me an error that the subscript is out of range. I know that the ChrPlace() variable is being loaded and it is declared in the module as the following:
Public ChrPlace() as integer
Public Function ParseString4aChar(Stringtxt As String, Chr As String, NumChr As Integer)
'This function will parse a string for a character and will return an array that contains
' the positions of the character in the string. The Numchr variable allows you to specify
'how many of the characters you expect in the string. If this variable is not known
'then specify 0.
Dim i, ChrPlace(), ChrCount As Integer
Dim tempchar As String
ReDim ChrPlace(NumChr - 1)
ChrCount = 0
'Scroll through each char
For i = 1 To Len(Stringtxt)
tempchar = Mid(Stringtxt, i, 1)
'Test to see if tempchar = char we are looking for
If tempchar = Chr Then
'if so increase index of array and test to see
'if all the characters have been found
ChrPlace(ChrCount) = i
ChrCount = ChrCount + 1
If (ChrCount = NumChr) And (Numchr <> 0) Then
Exit For
End If
End If
Next i
'Return the array
ParseString4aChar = ChrPlace()
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|