wannajmi
asked on
Read data in ( ) according to their order
Does anyone has a piece of VB code that can read data in a brackets For example (a, (b,c), d) according to their orders.
I think so, however, I need a bit more explanation for the purpose of this.
ASKER
I need a code that can read data inside a bracket and store in as a tree structure.
for example : (a,(b,(c,(d,(e,f))))) so the code will read the data inside the ( ), first e and f then d , then c , b and finaly a. and try to store in in a tree structure as
______________ a
|
____| ______ b
|__|
|_____ c and so on......
for example : (a,(b,(c,(d,(e,f))))) so the code will read the data inside the ( ), first e and f then d , then c , b and finaly a. and try to store in in a tree structure as
______________ a
|
____| ______ b
|__|
|_____ c and so on......
Hi,
For the reading part, it could be:
Private Sub Command1_Click()
a = "(a,(b,(c,(d,(e,f)))))"
List1.Clear
While a <> ""
Start = 1
b = InStr(Start, a, ")")
While InStr(Start, a, "(") > 0 And InStr(Start, a, "(") < b
c = InStr(Start, a, "(")
Start = c + 1
Wend
Read Mid(a, c + 1, b - c - 1)
a = Mid(a, 1, c - 1) & Mid(a, b + 1)
Wend
End Sub
Function Read(strText)
strText = strText & ","
While InStr(strText, ",") > 0
v = Mid(strText, 1, InStr(strText, ",") - 1)
strText = Mid(strText, InStr(strText, ",") + 1)
If Trim(v) <> "" Then
List1.AddItem v
End If
Wend
End Function
For the reading part, it could be:
Private Sub Command1_Click()
a = "(a,(b,(c,(d,(e,f)))))"
List1.Clear
While a <> ""
Start = 1
b = InStr(Start, a, ")")
While InStr(Start, a, "(") > 0 And InStr(Start, a, "(") < b
c = InStr(Start, a, "(")
Start = c + 1
Wend
Read Mid(a, c + 1, b - c - 1)
a = Mid(a, 1, c - 1) & Mid(a, b + 1)
Wend
End Sub
Function Read(strText)
strText = strText & ","
While InStr(strText, ",") > 0
v = Mid(strText, 1, InStr(strText, ",") - 1)
strText = Mid(strText, InStr(strText, ",") + 1)
If Trim(v) <> "" Then
List1.AddItem v
End If
Wend
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.