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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Reoccurring String 1

Status
Not open for further replies.

jibberski

Programmer
Aug 24, 2005
52
US
I'm trying to compile a list of Variables from a DB of stored formulas. Below is a basic 'if' statement with V(<VarName>) denoting the variables.

String to be parsed:
Code:
IF(V(# Diff Door Sizes)>0,V(Door 1 Count))

How can I loop through to parse the above string in order to store '# Diff Door Sizes' and 'Door 1 Count'.

Here's what I have so far:
Code:
Do While Not rst.EOF
        
        Calc = rst![Calculation]
        For Counter = 1 To Len(Calc)
          'Count V's in formula            
        Next Counter
         'for CounterB =1 to Number of v's  
             i = InStr(1, Calc, "V(", 1)
             j = InStr(i, Calc, ")", 1)
             'trim calc using i an j until no more 'V(' exist
             'store varname
          Next CounterB
           rst.MoveNext
     Loop
     rst.Close

Thanks for your time!
 
Perhaps something like:
Code:
    calc = Replace(calc, "))", ")")
    Do While InStr(calc, "V(") > 0
        'Count V's in formula
        strV = Mid(calc, InStr(calc, "V(") + 2, InStr(calc, ")") - (InStr(calc, "V(") + 2))
        Debug.Print strV
        calc = Mid(calc, InStr(1, calc, ")") + 1)
    Loop
 
Another way (ac2k or above):
Do While Not rst.EOF
Calc = rst![Calculation]
a = Split(Calc, "V(")
For i = IIf(Left(Calc, 2) = "V(", 0, 1) To UBound(a)
Debug.Print Left(a(i), InStr(a(i), ")") - 1)
Next

rst.MoveNext
Loop
rst.Close
Set rst = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top