Quote Originally Posted by ganeshmoorthy
try this...
VB Code:
  1. Private Sub Command1_Click()
  2.     Dim iSPos As Integer
  3.     Dim iEPos As Integer
  4.     Dim iNextSPos As Integer
  5.     Dim iNextEPos As Integer
  6.     Dim iLength As Integer
  7.  
  8.     iNextSPos = 1
  9.     iNextEPos = 1
  10.     iLength = Len(Trim(Text1.Text))
  11.     Do While i <= iLength
  12.         iSPos = InStr(iNextSPos, Text1.Text, "I ", vbTextCompare)
  13.         If iSPos > 0 Then
  14.             iEPos = InStr(iNextEPos, Text1.Text, " to ")
  15.             If iEPos > 0 Then
  16.                 Text2.Text = Text2.Text & Mid(Text1.Text, iSPos, (iEPos + 3) - iSPos) & vbCrLf
  17.                 iNextSPos = iEPos + 3
  18.                 iNextEPos = iEPos + 3
  19.                 i = i + iEPos
  20.             Else
  21.                 i = i + 1
  22.             End If
  23.         Else
  24.             i = i + 1
  25.         End If
  26.     Loop
  27. 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:
  1. Dim TxT, IStr, ToStr, ILoc, ToLoc, GLoc, Strng
  2. BeStr = " i "
  3. ThisStr = " to "
  4. GLoc = 1
  5. TxT = Text1.Text
  6. For oop = 1 To (Len(TxT) - 1)
  7.     ILoc = InStr(GLoc, TxT, IStr, vbTextCompare)
  8.     If ILoc > 0 Then
  9.    
  10.         ToLoc = InStr(GLoc, TxT, ToStr, vbTextCompare)
  11.         If ToLoc > 0 Then
  12.             GLoc = ToLoc + 1
  13.             Strng = Mid$(Text1.Text, ILoc + 1, (ToLoc + 3) - ILoc)
  14.             Text2.Text = Text2.Text & Strng & vbnewline
  15.         Else
  16.         oop = oop + 1
  17.         End If
  18.     Else
  19.     oop = oop + 1
  20.     End If
  21. Next
  22. End Sub