Eval function in VBA, but not VB?
Author |
Message |
Christopher Ke #1 / 10
|
 Eval function in VBA, but not VB?
Hi, I may be missing something very obvious, but I can find no VB equivalent of the VBA eval function. I am working on a project that will allow data to be entered in a wide variety of user definable units, and automatically convert them for storage as SI units. My hope was the user would be able to specify the formula for conversion to and from si units as a string, e.g. for inches to SI (metres), they would type "=Unit*.0254", which would be evaluated in an environment such that the variable 'unit' contained the value inputted. I am not keen to write my own version of the eval function, firstly as it is not a simple task to evaluate terms in the correct order from a standard string, and I do not want to subject my users to reverse polish notation, and secondly, as I see no way of accessing variable that are named in the string. Any help or advice would be much appreciated, Chris Key
|
Sat, 19 Jul 2003 06:55:56 GMT |
|
 |
Martin Trum #2 / 10
|
 Eval function in VBA, but not VB?
Quote: >I may be missing something very obvious, but I can find no VB equivalent of >the VBA eval function. I am working on a project that will allow data to be >entered in a wide variety of user definable units, and automatically convert >them for storage as SI units. My hope was the user would be able to specify >the formula for conversion to and from si units as a string, e.g. for inches >to SI (metres), they would type "=Unit*.0254", which would be evaluated in
Chris, any chance you could provide a separate textbox for each units type with labels saying Enter:- "Inches", "Feet", "Metres" and then convert, knowing where the entry was made? Just thought. Regards, -- Martin Trump
|
Sat, 19 Jul 2003 09:08:12 GMT |
|
 |
Christopher Ke #3 / 10
|
 Eval function in VBA, but not VB?
Quote: > Chris, any chance you could provide a separate textbox for each units > type with labels saying Enter:- "Inches", "Feet", "Metres" and then > convert, knowing where the entry was made?
Unfortunately not, the data is being entered via an LCD display, and space is very much at a premium. I had also hoped that other units could be entered after the program was completed, and thus avoid hard-coding the conversion into the program. I apologise for not being terribly clear, the program will be linking to an access database via ADO to store all the values entered by the user, and will retrive it's information on units from there, not from a box on the data entry form. If it is posible to remotely modify a query via ADO, and if a query using functions defined in a VBA could be accessed via ADO then this may be provide workable (although highly unelegant) solution. Chris Key
|
Sat, 19 Jul 2003 16:14:29 GMT |
|
 |
Christopher Ke #4 / 10
|
 Eval function in VBA, but not VB?
I have realied why the Eval function is excluded from VB, but not VBA. VBA is an interpreted language, and so the variable names will be accessible at run-time. VB however, is primarily a compiled language, and variables will have no referennce to the names used in programming. What this means is that if i write code to evaluate an expression, i will have to have the user specify a name and value for the main variable in the expression, and look up any other's in the constant table. Does anyone know of any code that will perform evaluation of numeric expressions? Chris Key
|
Sat, 19 Jul 2003 22:15:11 GMT |
|
 |
Larry Linso #5 / 10
|
 Eval function in VBA, but not VB?
Alas, it's a good theory, but VB hasn't always been able to be compiled, and I don't recall that it ever had an Eval function. VBA, by the way, can be "compiled to tokenized state" just as the "compilation" of earlier versions of VB, at least VBA in Microsoft Access. Tokenized VB could be, and was, "discompiled", but you can't get back meaningful labels, meaningful variable names, or comments because all those are lost in the compilation process. I guess nobody's thought that the available Access applications were worth the time and effort it would cost to create a discompiler as there used to be for tokenized VB, because I haven't heard of one.
Quote: > I have realied why the Eval function is excluded from VB, but not VBA. VBA > is an interpreted language, and so the variable names will be accessible at > run-time. VB however, is primarily a compiled language, and variables will > have no referennce to the names used in programming. What this means is that > if i write code to evaluate an expression, i will have to have the user > specify a name and value for the main variable in the expression, and look > up any other's in the constant table. Does anyone know of any code that will > perform evaluation of numeric expressions? > Chris Key
-- L. M. (Larry) Linson http://www.ntpcug.org - North Texas PC User Group - Visit and Join http://www.ntmsdevsigs.homestead.com - NTPCUG Developer SIGs http://homestead.deja.com/user.accdevel - Access examples Sent via Deja.com http://www.deja.com/
|
Sun, 20 Jul 2003 01:13:45 GMT |
|
 |
Ian #6 / 10
|
 Eval function in VBA, but not VB?
You can use the Script Control, which you can download from here http://msdn.microsoft.com/scripting/ regards Ian ** invalid email address, change dk to denmark homepage http://www.kingsoft-denmark.com/ Tips & Tricks page http://tips.kingsoft-denmark.com/
Quote: > Alas, it's a good theory, but VB hasn't always been able to be > compiled, and I don't recall that it ever had an Eval function. > VBA, by the way, can be "compiled to tokenized state" just as > the "compilation" of earlier versions of VB, at least VBA in Microsoft > Access. Tokenized VB could be, and was, "discompiled", but you can't > get back meaningful labels, meaningful variable names, or comments > because all those are lost in the compilation process. > I guess nobody's thought that the available Access applications were > worth the time and effort it would cost to create a discompiler as > there used to be for tokenized VB, because I haven't heard of one.
> > I have realied why the Eval function is excluded from VB, but not > VBA. VBA > > is an interpreted language, and so the variable names will be > accessible at > > run-time. VB however, is primarily a compiled language, and variables > will > > have no referennce to the names used in programming. What this means > is that > > if i write code to evaluate an expression, i will have to have the > user > > specify a name and value for the main variable in the expression, and > look > > up any other's in the constant table. Does anyone know of any code > that will > > perform evaluation of numeric expressions? > > Chris Key > -- > L. M. (Larry) Linson > http://www.ntpcug.org - North Texas PC User Group - Visit and Join > http://www.ntmsdevsigs.homestead.com - NTPCUG Developer SIGs > http://homestead.deja.com/user.accdevel - Access examples > Sent via Deja.com > http://www.deja.com/
|
Sun, 20 Jul 2003 01:27:11 GMT |
|
 |
Larry Linso #7 / 10
|
 Eval function in VBA, but not VB?
Have you considered the possibility of doing something with VBScript? You don't have to have a very recent system to have Windows Scripting Host to run it.
Quote: > Hi, > I may be missing something very obvious, but I can find no VB equivalent of > the VBA eval function. I am working on a project that will allow data to be > entered in a wide variety of user definable units, and automatically convert > them for storage as SI units. My hope was the user would be able to specify > the formula for conversion to and from si units as a string, e.g. for inches > to SI (metres), they would type "=Unit*.0254", which would be evaluated in > an environment such that the variable 'unit' contained the value inputted. I > am not keen to write my own version of the eval function, firstly as it is > not a simple task to evaluate terms in the correct order from a standard > string, and I do not want to subject my users to reverse polish notation, > and secondly, as I see no way of accessing variable that are named in the > string. > Any help or advice would be much appreciated, > Chris Key
-- L. M. (Larry) Linson http://www.ntpcug.org - North Texas PC User Group - Visit and Join http://www.ntmsdevsigs.homestead.com - NTPCUG Developer SIGs http://homestead.deja.com/user.accdevel - Access examples Sent via Deja.com http://www.deja.com/
|
Sun, 20 Jul 2003 01:15:35 GMT |
|
 |
coreDum #8 / 10
|
 Eval function in VBA, but not VB?
yes aplenty, ranging from simple calculators to symbolic math programs like Mathematica. what you want/need is a parser. Peet Quote:
> I have realied why the Eval function is excluded from VB, but not VBA. VBA > is an interpreted language, and so the variable names will be accessible at > run-time. VB however, is primarily a compiled language, and variables will > have no referennce to the names used in programming. What this means is that > if i write code to evaluate an expression, i will have to have the user > specify a name and value for the main variable in the expression, and look > up any other's in the constant table. Does anyone know of any code that will > perform evaluation of numeric expressions? > Chris Key
|
Sun, 20 Jul 2003 04:36:39 GMT |
|
 |
eb #9 / 10
|
 Eval function in VBA, but not VB?
Chris, The Microsoft Scripting Control (MSSCRIPT.OCX) has an Eval function. If you don't have it, you can probably get it from the MSDN site. Eric
Quote: >I have realied why the Eval function is excluded from VB, but not VBA. VBA >is an interpreted language, and so the variable names will be accessible at >run-time. VB however, is primarily a compiled language, and variables will >have no referennce to the names used in programming. What this means is that >if i write code to evaluate an expression, i will have to have the user >specify a name and value for the main variable in the expression, and look >up any other's in the constant table. Does anyone know of any code that will >perform evaluation of numeric expressions? >Chris Key
|
Sun, 20 Jul 2003 08:20:02 GMT |
|
 |
Martin Trum #10 / 10
|
 Eval function in VBA, but not VB?
deja.com> writes Quote: >Alas, it's a good theory, but VB hasn't always been able to be >compiled, and I don't recall that it ever had an Eval function.
Years ago I wrote an eval function in assembler code for a m/c now long gone. Would one in pure VB6 be of general use? Comments invited. Regards, -- Martin Trump
|
Sun, 20 Jul 2003 08:28:40 GMT |
|
|
|