Sub test()
Dim sng As Single
Dim strExpression As String
strExpression = “60+144”
‘ Dim strVar As Variant
‘ strVar = strExpression
‘ sng = evaluate(strVar)
sng = CSng(strExpression)
End Sub
I have been struggling off and on throughout the day to resolve the arithmetic value of a presented string.
I am given an x,y co-ordinate as a line of a text file:-
ORIGIN 60+144,111
and I want to obtain the horizontal co-ordinate as 204. For input into a Shapes.AddLine statement, since you ask.
Excel has an Evaluate function – sng = Evaluate(strExpression) – which works very well in Excel2003.
But I am staggered that I cannot perform a straight arithmetic calculation from a string in Word2003 VBA.
I have previously used =Formula to insert a crafted SUM function in a Word2003 Table, but would appreciate any tips on how to do simple arithmetic from a string expression within VBA.
The application is basically simulating a flatbed plotter, and moves the pen (raised or lowered) between pairs of points. If a room is two rooms down and the rooms are sixty inches and one hundred forty four inches, it is convenient for the user to transcribe this data as “ORIGIN 60+144,111” rather than trust to the user’s mental arithmetic.
Besides which, computers are good at doing boring and repetitive work.
Thank you
Chris Greaves
Unless you're in a hurry, just wait.