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
-
Do someone has free barcode vb6 control?
by bruce.harvey (13 replies)
-
Project load errors in vb6
by docjump (0 replies)
-
Howto make a multipleline textbox auto scroll down
by jokopratomoadi (5 replies)
-
Compress a picture using VB6
by Wallism (3 replies)
-
Windows 8 Metro Video App to Play a Movie
by EJH007 (0 replies)
MS Access podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 2 months 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