Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting text inside brackets from a text box

Status
Not open for further replies.

ftpdoo

Programmer
Aug 9, 2001
202
GB
Hi,

I have a text box (txtText) which contains an SQL statement as follows:

INSERT INTO myTable VALUES(<WorkOrder>, <FreeText>, <Fixed>)

I'm trying to extract the values inside the angled brackets (ie WorkOrder, FreeText, Fixed) and to place these values into three separate text boxes.

Thankx in advance,
Jonathan
 
Hi Jonathan!

You can use the following procedure:

*********Untested Code*************

Dim lngFirstBracket As Long
Dim lngSecondBracket As Long
Dim strTextBoxInfo As String
Dim lngBracketPosition As Long
Dim strTestString As String
Dim strFieldValue As String
Dim intTextBoxCounter As Integer

strTextBoxInfo = txtText.Value
lngBracketPosition = InStr(strTextBoxInfo, &quot;<&quot;)
lngFirstBracket = lngBracketPosition
intTextBoxCounter = 1
Do Until lngBracketPosition = 0
If lngFirstBracket = 0 Then
lngFirstBracket = lngBracketPosition
strTestString = &quot;>&quot;
lngBracketPosition = InStr(lngFirstBracket, strTextBoxInfo, strTestString)
Else
If lngBracketPosition <> lngFirstBracket Then
lngSecondBracket = lngBracketPosition
srtFieldValue = Mid(strTextBoxInfo, lngFirstBracket + 1, lngSecondBracket - lngFirstBracket - 1)
Select Case intTextBoxCounter
Case 1
FirstTextBox = strFieldValue
Case 2
SecondTextBox = strFieldValue
Etc.
End Select
strTestString = &quot;<&quot;
lngFirstBracket = 0
lngBracketPosition = InStr(lngSecondBracket, strTextBoxInfo, strTestString)
End If
End If
Loop

I think this will work for you.

hth
Jeff Bridgham
 
Thankx,

But this goes into an infinate loop on the following line and also around the DO WHILE as both longs contain the same value (ie 30):

If lngBracketPosition <> lngFirstBracket Then

Any idea's??
Jonathan
 
Hi!

You're right! You will need to set both the positions for the first and second brackets before going into the loop and take away the If lngBracketPosition <> lngFirstBracket Then condition. That's what I get for writing code when I don't have time to test it!

hth
Jeff Bridgham Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top