If you have never coded in java or a similiar language subs and functions are generally seperated by the { and } characters. I was looking to see if anyone had code to match up these characters. In other words, if someone were to click on a text box on the { (open) character, I would like for the } (close) character to be selected as well.
Anyone??
In case of a water landing, my head may be used as a flotation device.
Mainly what I am looking for is some sort of sorting sequence that will match up the pairs of {'s and }'s. And save them in a type, lets say :
Public type bracketPairs
openBracketPosition as integer
closeBracketPosition as integer
end type
When a matching pair is found, bracketPairs.openBracketPosition = location of open bracket and the same for closed bracket position. I am just having a hard time matching up the pairs.
In case of a water landing, my head may be used as a flotation device.
Do you mean, for example, if you had the following string.
int main
{
cout "Blah" << endl;
for(int i=0;i<10;i++)
{
cout << i << endl;
}
return 0;
}
When you select the opening brace in a text box, all data between the opening, and matched up ending brace is selected? So if i selected the first brace, the following would be selected:
Digital - exactly. But I am not worried about how to highlight them. I am just looking to locate matching pairs. Displaying or highlighting them is simple enough.
In case of a water landing, my head may be used as a flotation device.
In a module:
Public Type openBrackets
position As Integer
matchingClosed As Integer
End Type
Public Type closedBrackets
position As Integer
matchingOpen As Integer
End Type
Public oB() As openBrackets
Public cB() As closedBrackets
My parsing sub:
Public Sub findBrackets()
Dim x As Integer
Dim y As Integer
Dim xCount As Integer
Dim yCount As Integer
Dim startAt As Integer
x = 1
While InStr(x, RTB.Text, "{") > 0
x = InStr(x, RTB.Text, "{")
xCount = xCount + 1
If xCount = 1 Then
ReDim oB(1)
Else
ReDim Preserve oB(xCount)
End If
oB(xCount).position = x
x = x + 1
Wend
x = 1
While InStr(x, RTB.Text, "}") > 0
x = InStr(x, RTB.Text, "}")
yCount = yCount + 1
If yCount = 1 Then
ReDim cB(1)
Else
ReDim Preserve cB(yCount)
End If
cB(yCount).position = x
x = x + 1
Wend
While allFilled = False 'all filled is a boolean function denoting the existance of a number in the .matchingOpen and .matchingClosed
For x = 1 To UBound(oB) - 1
If oB(x).matchingClosed = 0 Then
For y = 1 To UBound(cB)
If cB(y).position > oB(x).position And cB(y).matchingOpen = 0 Then
If cB(y).position < oB(x + 1).position And cB(y).matchingOpen < 1 Then
oB(x).matchingClosed = cB(y).position
cB(y).matchingOpen = oB(x).position
Exit For
Else
Exit For
End If
End If
Next y
End If
Next x
Wend
End Sub
In case of a water landing, my head may be used as a flotation device.
Unfortunately, no. It gets stuck in a loop. Don't know why either. I know I can eventually solve thison my own, I was just hoping someone had already done a similiar routine and I could just borrow theirs.
In case of a water landing, my head may be used as a flotation device.