• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Visual Basic Read Tokens using a Delimiter

Status
Not open for further replies.

Kaway

Banned
User
Joined
Aug 7, 2014
Messages
720
Reputation
0
Reaction score
5,766
Points
243
Credits
0
‎10 Years of Service‎
15%
Please note, if you want to make a deal with this user, that it is blocked.
[HIDE-THANKS]ParameterValue() and ParameterCount() allow you to parse out "words" from a text string. Lets say TheString is "This,is,a,test". ParameterCount(",",TheString) will return 4 and ParameterValue(",",TheString,2) will return "is".

Code:
>Public Function ParameterValue(ParseCharacter As String, _
                              tString As Variant, _
                              Index As Integer) As String

'USAGE: Debug.Print ParameterValue(",", "A,B,C,D,E", 4)
'Prints "D" to the Debug Window
 Dim CurrentPosition As Integer
 Dim ParseToPosition As Integer
 Dim CurrentToken As Integer
 Dim TempString As String
 TempString = Trim(tString) + ParseCharacter
 If Len(TempString) = 1 Then Exit Function
 CurrentPosition = 1
 CurrentToken = 1
 Do
   ParseToPosition = InStr(CurrentPosition, TempString, _
                           ParseCharacter)
   If Index = CurrentToken Then
     ParameterValue = Mid$(TempString, CurrentPosition, _
                           ParseToPosition - CurrentPosition)
     Exit Function
   End If
   CurrentToken = CurrentToken + 1
   CurrentPosition = ParseToPosition + 1
 Loop Until (CurrentPosition >= Len(TempString))
End Function

Public Function ParameterCount(ParseCharacter As String, _
                              tString As Variant) As Integer
           
'USAGE: ParameterCount(",", "A,B,C,D,E")
'Prints "5" to the Debug Window
 Dim CurrentPosition As Integer
 Dim ParseToPosition As Integer
 Dim CurrentToken As Integer
 Dim TempString As String
 TempString = Trim(tString) + ParseCharacter
 If Len(TempString) = 1 Then Exit Function
 CurrentPosition = 1
 CurrentToken = 1
 Do
     ParseToPosition = InStr(CurrentPosition, TempString, _
                             ParseCharacter)
     CurrentToken = CurrentToken + 1
     CurrentPosition = ParseToPosition + 1
 Loop Until (CurrentPosition >= Len(TempString))
 ParameterCount = CurrentToken - 1
End Function
[/HIDE-THANKS]

 
Status
Not open for further replies.
Back
Top