Sub test()
chaine = "3*2*8*4.5+10/(1.5*2)-4*2"
If chaine Like "*(*)*" Then chaine = HTMLparser(chaine)
chaine = PutPrioritySegment(chaine)
chaine = HTMLparser(chaine)
End Sub
Function PutPrioritySegment(chaine)
Dim elem, i&, t
For Each elem In Array("+", "-", "*", "/"): chaine = Replace(chaine, elem, "|" & elem): Next
chaine = Replace(chaine, "/", "*/")
Do While InStr(chaine, "*") > 0
t = Split(chaine, "|")
For i = 1 To UBound(t)
If InStr(t(i), "*") Then t(i - 1) = "(" & t(i - 1): t(i - 1) = t(i - 1) & Replace(t(i), "*", "x") & ")": t(i) = "": Exit For
Next
chaine = Replace(Replace(Replace(Replace(Join(t, ""), "*", "|*"), "+", "|+"), "-", "|-"), ":", "|:")
'Debug.Print chaine
Loop
chaine = Replace(Replace(Replace(chaine, "(|+", "+("), "(|-", "-("), "(|:", "/(")
chaine = Replace(chaine, "(+", "+(")
chaine = Replace(chaine, "x/", "/")
chaine = Replace(chaine, "|", "")
PutPrioritySegment = chaine
End Function
Function HTMLparser(chaine)
Debug.Print "original:" & chaine
'chaine = PutPrioritySegment(chaine)
Debug.Print "priority:" & chaine
With CreateObject("htmlfile")
.body.innerhtml = Replace(Replace(chaine, "(", "<DIV>"), ")", "</DIV>")
Debug.Print Replace(.body.innerhtml, vbCrLf, "")
Debug.Print "-"
For e = 1 To 10
Set elem = .getelementsbytagname("DIV")
If elem.Length = 0 Then Exit For
For i = 0 To elem.Length - 1
If elem(i).Children.Length = 0 Then
'If elem(i).innerhtml Like "*x*" Then
oldSegment = elem(i).innertext
x = Evaluate(Replace(elem(i).innertext, "x", "*"))
MsgBox elem(i).innerhtml & vbCrLf & elem(i).NodeType
If Not IsError(x) Then elem(i).outerhtml = x
Exit For
'End If
End If
Next
Debug.Print "priorité:" & oldSegment & "=" & x
Debug.Print Replace(Replace(Replace(.body.innertext, "<div>", ""), "</div>", ""), vbCrLf, "")
Next
HTMLparser = Replace(Replace(Replace(.body.innertext, "<div>", ""), "</div>", ""), vbCrLf, "")
End With
End Function