Libertarious
New Member
- Joined
- Mar 12, 2014
- Messages
- 7
I'm creating an algebraic equation solver.
The equation I have entered into the cell is:
8|x+3|−2=−4|x+3|+8
I've successfully isolated all the terms and coefficients into a Public Type with string members.
When I attempt to evaluate actual values via Val(string), my positive numbers resolve to expected numeric values, while my negative string numbers are resolved to 0.
Relevant Code Excerpt:
Public Function SolveAbsoluteEquation(AbsEquation As String) As String
...
.LeftTerm.AbsoluteTerm.Coefficient = Mid(EquationLeft, 1, DelimiterIndex - 1)
Debug.Print "STR=" & .LeftTerm.AbsoluteTerm.Coefficient
Debug.Print "VAL=" & Val(.LeftTerm.AbsoluteTerm.Coefficient)
.LeftTerm.AbsoluteTerm.ComplexTerm = Mid(EquationLeft, DelimiterIndex, CaptureLenghtIndex + 1)
Debug.Print "STR=" & .LeftTerm.AbsoluteTerm.ComplexTerm
.LeftTerm.UnitTerm = Right(EquationLeft, Len(EquationLeft) - (CaptureLenghtIndex + DelimiterIndex))
Debug.Print "STR=" & .LeftTerm.UnitTerm
Debug.Print "VAL=" & Val(.LeftTerm.UnitTerm)
DelimiterIndex = InStr(1, EquationRight, "|")
.RightTerm.AbsoluteTerm.Coefficient = Mid(EquationRight, 1, DelimiterIndex - 1)
Debug.Print "STR=" & .RightTerm.AbsoluteTerm.Coefficient
Debug.Print "VAL=" & Val(.RightTerm.AbsoluteTerm.Coefficient)
.RightTerm.AbsoluteTerm.ComplexTerm = Mid(EquationRight, DelimiterIndex, CaptureLenghtIndex + 1)
Debug.Print "STR=" & .RightTerm.AbsoluteTerm.ComplexTerm
.RightTerm.UnitTerm = Right(EquationRight, Len(EquationRight) - (CaptureLenghtIndex + DelimiterIndex))
Debug.Print "STR=" & .RightTerm.UnitTerm
Debug.Print "VAL=" & Val(.RightTerm.UnitTerm)
...
End Function
My Debug.Print results are:
STR=8
VAL=8
STR=|x+3|
STR=-2
VAL=0???
STR=-4
VAL=0???
STR=|x+3|
STR=+8
VAL=8
I've tried Trim(string), still fails to properly resolve as expected.
The only way I did get it to resolve was to force my passed input string to the literal: "8|x+3|−2=−4|x+3|+8"
STR=8
VAL=8
STR=|x+3|
STR=-2
VAL=-2
STR=-4
VAL=-4
STR=|x+3|
STR=+8
VAL=8
The equation I have entered into the cell is:
8|x+3|−2=−4|x+3|+8
I've successfully isolated all the terms and coefficients into a Public Type with string members.
When I attempt to evaluate actual values via Val(string), my positive numbers resolve to expected numeric values, while my negative string numbers are resolved to 0.
Relevant Code Excerpt:
Public Function SolveAbsoluteEquation(AbsEquation As String) As String
...
.LeftTerm.AbsoluteTerm.Coefficient = Mid(EquationLeft, 1, DelimiterIndex - 1)
Debug.Print "STR=" & .LeftTerm.AbsoluteTerm.Coefficient
Debug.Print "VAL=" & Val(.LeftTerm.AbsoluteTerm.Coefficient)
.LeftTerm.AbsoluteTerm.ComplexTerm = Mid(EquationLeft, DelimiterIndex, CaptureLenghtIndex + 1)
Debug.Print "STR=" & .LeftTerm.AbsoluteTerm.ComplexTerm
.LeftTerm.UnitTerm = Right(EquationLeft, Len(EquationLeft) - (CaptureLenghtIndex + DelimiterIndex))
Debug.Print "STR=" & .LeftTerm.UnitTerm
Debug.Print "VAL=" & Val(.LeftTerm.UnitTerm)
DelimiterIndex = InStr(1, EquationRight, "|")
.RightTerm.AbsoluteTerm.Coefficient = Mid(EquationRight, 1, DelimiterIndex - 1)
Debug.Print "STR=" & .RightTerm.AbsoluteTerm.Coefficient
Debug.Print "VAL=" & Val(.RightTerm.AbsoluteTerm.Coefficient)
.RightTerm.AbsoluteTerm.ComplexTerm = Mid(EquationRight, DelimiterIndex, CaptureLenghtIndex + 1)
Debug.Print "STR=" & .RightTerm.AbsoluteTerm.ComplexTerm
.RightTerm.UnitTerm = Right(EquationRight, Len(EquationRight) - (CaptureLenghtIndex + DelimiterIndex))
Debug.Print "STR=" & .RightTerm.UnitTerm
Debug.Print "VAL=" & Val(.RightTerm.UnitTerm)
...
End Function
My Debug.Print results are:
STR=8
VAL=8
STR=|x+3|
STR=-2
VAL=0???
STR=-4
VAL=0???
STR=|x+3|
STR=+8
VAL=8
I've tried Trim(string), still fails to properly resolve as expected.
The only way I did get it to resolve was to force my passed input string to the literal: "8|x+3|−2=−4|x+3|+8"
STR=8
VAL=8
STR=|x+3|
STR=-2
VAL=-2
STR=-4
VAL=-4
STR=|x+3|
STR=+8
VAL=8
Last edited: