How to evaluate expression entered in an autocad VBA textbox??

How to evaluate expression entered in an autocad VBA textbox??

autodeskT3FR5
Explorer Explorer
1,053 Views
1 Reply
Message 1 of 2

How to evaluate expression entered in an autocad VBA textbox??

autodeskT3FR5
Explorer
Explorer

Hello,

 

I am fairly new to Autocad as well as VBA.  This is more of a VBA than Autocad question.. hope its ok to ask here.  I have a simple VBA program where I can enter X and Y dimensions, draw boxes, draw circles, create custom layer names etc, but I am having trouble getting my text boxes to interpret anything other than simple numbers.

 

I want to have it so that the text boxes in my forms can understand inputs such as 60+224 or X+32 where X is previously defined somewhere else and be able to evaluate these expressions rather than interpret as a string.

 

Also worth noting, I am still mostly at the "copy snippets from the internet and adjust accordingly" phase in my understanding of VBA coding..  OOP is still pretty new to me.

 

I've been trying both the Eval and Evaluate functions but with no success.

 

experiments I've tried with a form that has a button, textbox for input and label for output:

 

Private Sub btnGo_Click()

     lblOutput.caption = Eval (txtInput.value)

end Sub

 

this results in an error : Expected function or Variable

 

Private Sub btnGo_Click()

     Eval(txtInput.value)

     lblOutput.caption = txtInput.value

End sub

 

this results in a runtime error : VBA expression evaluation failed.

 

Hoping somebody can help me with this.

 

Thanks

0 Likes
1,054 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

There are in general 2 options: using an existing available component (script engine/control), or develop your own.

 

For the former. Microsoft Script Control 1.0 is the one used by most VBA applications for simple scripting task. However, it is a 32-bit COM component, you can only use it in AutoCAD VBA if you use AutoCAD 2013 or older version, or later 32-bit version of AutoCAD up to 2019. In reality, virtually no one still use 32-bit AutoCAD, so, unfortunately this would likely not be usable for you. There is no 64-bit COM scripting control available AFAIK.

If the expression is very simple, such as only do straight adding/substracting/multiplying/dividing, you could code your own "scripting engine" with VBA code, if you up to the task. Most likely it would not worth the effort of doing it.

 

If you do AutoCAD .NET programming, it would a few easy options.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes