If you've come to Visual Basic from Microsoft Access, you probably
miss the handy Eval() method. This method evaluates a supplied
string as though it were code. As a result, you could easily
evaluate mathematical expressions passed as a string, like so:iResult = Eval("(2 * 3) + 5)")
which fills iResult with the value 11.
To achieve this same functionality in Visual Basic, you've no doubt
resorted to complicated string parsing functions. Or perhaps you
added Access' DLL to your project, which may have seemed like an
awful lot of DLL for such a simple method.
Now, though, you'll be happy to know that you can use the
Eval() method without a lot of overhead. Microsoft provides this
functionality in its Script Control. This very lightweight ActiveX
component is available so you can add end-user scripting ability
to your applications. However, as a result, it also comes with
an Eval method. Adding this component to your project provides
very little overhead and gives you the ability to evaluate
mathematical strings.
To download this OCX, visit http://msdn.microsoft.com/scripting/
Select the Script Control link, then follow the Download
instructions. The following code shows the simple VB we added
to a command button's click event. The SC1 script control
evaluates a mathematical formula in the txtFormula textbox.Private Sub Command1_Click()
MsgBox txtFormula & " = " & SC1.Eval(txtFormula)
End Sub
Evaluate string formulas in VB
By ElementK Journals, published on 14 Jul 2001
| Filed in
You might also like...
MS Access forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
-
is it possible to create exe file for access file
by swiftprosoftware.dm (17 replies)
MS Access podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 7 years ago, running time 0h54m
Our guest this week is Eric Lippert – language architect extraordinaire and famous for all his work at Microsoft in developing their languages Eric joined Microsoft right out of college and was originally working on VB It’s time for everyone’s favorite game: Name the Worst Feature of that Microso.
Comments