PDA

View Full Version : Solved: InString Function



kbsudhir
10-05-2008, 01:13 PM
Guys,

I am using Instr function find the position of words in my string.

Do Until StrLen = DataLen

Pos = InStr(StrPos, Data, ",", vbTextCompare)
GtData = Mid(Data, 1, Pos + 1)
GtData = Trim(Replace(GtData, ", ", ""))
StrLen = Pos + 1
StrPos = Pos

MsgBox GtData

Loop


In the above code I am changing the startpoint of the search position.
But each time Instr string is starting from the 1st character & giving back the same position.

Ex in string "father, mother, Son"
First is should return position of "," as 6
then again as 8 but it is again returning "6"

Any help on this is appreciated.

Sudhir

Bob Phillips
10-05-2008, 01:43 PM
Pos = -1
Do Until StrLen = DataLen Or Pos = 0

Pos = InStr(StrPos, Data, ",", vbTextCompare)
GtData = Mid(Data, 1, Pos + 1)
GtData = Trim(Replace(GtData, ", ", ""))
StrLen = Pos + 1
StrPos = Pos + 1

MsgBox GtData
Loop