Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval-method in VB???

Status
Not open for further replies.

theemperor

Programmer
May 22, 2001
28
AT
Hi there!
Can someone tell me whether there is something like an eval-method, which handles a string like a variable or const?

thx in advance,
Robert
 
Your question isn't too clear. Are you asking for:

val()

"Returns the numbers contained in a string as a numeric value of appropriate type"

elziko
 
you want a function like val() that works for strings... well, you dont need one.

say:
myVar = text1

maybe u need to trim it (get rid of extra spaces)

myVar = trim(text1)

I dont see what the problem is
 
I assume you are trying to determine the result of an oper or function (example eval(1+1) and receive the answer 2???)

To do that in the IDE just put the expression in a Debug.Print function:

Example:- Debug.Print Replace$("xxxBxxx", "x", "c") shows "cccBccc"

Does this assist??????
 
Thanx to all of you. The val()-method helped!

regards robert
 
I tried to use the val()-method, but it always returns 0 as my string doesn't contain any numbers. I've got a two modules, where one of them contains a lot of constants. In the other module, I read some configuration data from an xml-file. The problem is that I get strings back and therefore can't use them as constants! My question was, whether there is a function or workaround which "converts" my strings from the xml-file to constants that I use in my main module!

thx in advance, Robert
 
The VAL command converts numeric data stored as a string to a numeric type, but it stops when it gets to the first non-numeric value. If you pass in a string to it, you will always get 0.
You can reference method and variables as strings using the CallByName function, but there are some limitations to it . . . could you post the code that you are tring to work with and I look at it and tell you if the CallByName function will work. - Jeff Marler B-)
 
Hi,
VB does not have an Eval() method as MSAccess.
If you need to evaluate mathematical expresions passed as a string, i.e.
iResult=Eval("3*4 + 5 - 1") which returns 16
then you may use the Microsoft Script Control.

You can download the script control from the following Web site:

Note: The Script control ships with Visual Basic 6 but, Visual Basic 6 setup does not install the Script Control for you.
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top