
Originally Posted by
ganeshmoorthy
try this...
VB Code:
Private Sub Command1_Click()
Dim iSPos As Integer
Dim iEPos As Integer
Dim iNextSPos As Integer
Dim iNextEPos As Integer
Dim iLength As Integer
iNextSPos = 1
iNextEPos = 1
iLength = Len(Trim(Text1.Text))
Do While i <= iLength
iSPos = InStr(iNextSPos, Text1.Text, "I ", vbTextCompare)
If iSPos > 0 Then
iEPos = InStr(iNextEPos, Text1.Text, " to ")
If iEPos > 0 Then
Text2.Text = Text2.Text & Mid(Text1.Text, iSPos, (iEPos + 3) - iSPos) & vbCrLf
iNextSPos = iEPos + 3
iNextEPos = iEPos + 3
i = i + iEPos
Else
i = i + 1
End If
Else
i = i + 1
End If
Loop
End Sub
Code:
Thanks for great help
i changed it to be perfect with lines may contains more than one case of the condition
VB Code:
Dim TxT, IStr, ToStr, ILoc, ToLoc, GLoc, Strng
BeStr = " i "
ThisStr = " to "
GLoc = 1
TxT = Text1.Text
For oop = 1 To (Len(TxT) - 1)
ILoc = InStr(GLoc, TxT, IStr, vbTextCompare)
If ILoc > 0 Then
ToLoc = InStr(GLoc, TxT, ToStr, vbTextCompare)
If ToLoc > 0 Then
GLoc = ToLoc + 1
Strng = Mid$(Text1.Text, ILoc + 1, (ToLoc + 3) - ILoc)
Text2.Text = Text2.Text & Strng & vbnewline
Else
oop = oop + 1
End If
Else
oop = oop + 1
End If
Next
End Sub