'replace ',' as '&"*"&'
newcode="test test(test,test,test(),")","(","test,",",test") test"
lastc="test("
i=StrIndexOf(newcode,lastc,i)
i=i+StrLength(lastc)
'find ')'
i1=StrIndexOf(newcode,")",i)
'check for '"...)..."'
i2=StrIndexOf(newcode,Chr(34),i)
i3=StrIndexOf(newcode,Chr(34),i2+1)
s=0
If i1>i2 AND i1<i3 Then s=1
Do While s=1
s=0
i1=StrIndexOf(newcode,")",i3)
i2=StrIndexOf(newcode,Chr(34),i3+1)
If i1<>-1 AND i2<>-1 Then
i3=StrIndexOf(newcode,Chr(34),i2+1)
If i1>i2 AND i1<i3 Then s=1
End If
Loop
'find '('
i2=StrIndexOf(newcode,"(",i)
'check for '"...(..."'
i3=StrIndexOf(newcode,Chr(34),i)
i4=StrIndexOf(newcode,Chr(34),i3+1)
s=0
If i2>i3 AND i2<i4 Then s=1
Do While s=1
s=0
i2=StrIndexOf(newcode,"(",i4)
i3=StrIndexOf(newcode,Chr(34),i4+1)
If i2<>-1 AND i3<>-1 Then
i4=StrIndexOf(newcode,Chr(34),i3+1)
If i2>i3 AND i2<i4 Then s=1
End If
Loop
'find index of last ')'
If i2<>-1 Then
Do While i2<i1
i3=i1
i1=StrIndexOf(newcode,")",i3+1)
i2=StrIndexOf(newcode,"(",i3+1)
If i2=-1 Then i2=i1+1
Loop
End If
Msgbox(SubString(newcode,i,i1-i))