Shaggyra
Posts: 608
Joined: 2/10/2006 Status: offline
|
Some code to help you. Option Compare Database Function CountCSWords(ByVal S) As Integer ' Counts the words in a string that are separated by commas. Dim WC As Integer, Pos As Integer If VarType(S) <> 8 Or Len(S) = 0 Then CountCSWords = 0 Exit Function End If WC = 1 Pos = InStr(S, "/") Do While Pos > 0 WC = WC + 1 Pos = InStr(Pos + 1, S, "/") Loop CountCSWords = WC End Function Function GetCSWord(ByVal S, Indx As Integer) ' Returns the nth word in a specific field. Dim WC As Integer, Count As Integer, SPos As Integer, EPos As Integer WC = CountCSWords(S) If Indx < 1 Or Indx > WC Then GetCSWord = Null Exit Function End If Count = 1 SPos = 1 For Count = 2 To Indx SPos = InStr(SPos, S, "/") + 1 Next Count EPos = InStr(SPos, S, "/") - 1 If EPos <= 0 Then EPos = Len(S) GetCSWord = Trim(Mid(S, SPos, EPos - SPos + 1)) End Function Function CountWords(ByVal S) As Integer ' Counts the words in a string that are separated by commas. Dim WC As Integer, Pos As Integer If VarType(S) <> 8 Or Len(S) = 0 Then CountWords = 0 Exit Function End If WC = 1 Pos = InStr(S, ":") Do While Pos > 0 WC = WC + 1 Pos = InStr(Pos + 1, S, ":") Loop CountWords = WC End Function Function GetWord(ByVal S, Indx As Integer) ' Returns the nth word in a specific field. Dim WC As Integer, Count As Integer, SPos As Integer, EPos As Integer WC = CountWords(S) If Indx < 1 Or Indx > WC Then GetWord = Null Exit Function End If Count = 1 SPos = 1 For Count = 2 To Indx SPos = InStr(SPos, S, ":") + 1 Next Count EPos = InStr(SPos, S, ":") - 1 If EPos <= 0 Then EPos = Len(S) GetWord = Trim(Mid(S, SPos, EPos - SPos + 1)) End Function Example: Yards = GetWord(GetCSWord([Statvalues],2),2) Long: GetWord(GetCSWord([Statvalues],3),2) TD: GetWord(GetCSWord([Statvalues],4),2)
< Message edited by Shaggyra -- 10/4/2008 7:28:37 PM >
_____________________________
|