Link to home
Start Free TrialLog in
Avatar of wannajmi
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.
Avatar of Jacamar
Jacamar

I think so, however, I need a bit more explanation for the purpose of this.
Avatar of wannajmi

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......
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
ASKER CERTIFIED SOLUTION
Avatar of Shaka913
Shaka913

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial