473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Can Eval evaluate a date arithmetic expression?

For some odd reason, I am trying to do some complex time calculations
that I want to let the user define. So I set up a table with

EventID EventType EventExpression
1 SolarNoon datediff("n",Sunrise,Sunset)
etc.

This is supposed to be evaluated with
TimeofNoon=Eval(EventExpression)

Unfortunately, it keeps telling me it doesn't recognize Sunrise,
whether it's a control on the form, or a publicly declared variable,
or part of a publicly declared class.
I also tried using single quotes in the expression to be evaluated.
I also tried enclosing the eval in another layer:
Function EvaluateExpression(stExpression As String)
EvaluateExpression = Eval(stExpression)
End Function
Of course, if I go to debug and do
?stExpression
and then put a ? in front of the result, it works just fine!

I could just forget all this and use case statements. However, I
wanted to leave room for a user to add some calculation that didn't
occur to me. Can it be done?
Nov 13 '05 #1
1 3218
Eval has no idea about anything on a form unless yuo tell it which form, so
you should be able to change the expression to
datediff("n",[Forms]![frmMyForm]![Sunrise],[Forms]![frmMyForm]![Sunset]). If
you want to use an expression from code, Eval can see public functions, but
not variables, so you would have to create a function that returns the value
from the variable.

On 28 Nov 2004 23:11:26 -0800, pe***********@aol.com (Penguin) wrote:
For some odd reason, I am trying to do some complex time calculations
that I want to let the user define. So I set up a table with

EventID EventType EventExpression
1 SolarNoon datediff("n",Sunrise,Sunset)
etc.

This is supposed to be evaluated with
TimeofNoon=Eval(EventExpression)

Unfortunately, it keeps telling me it doesn't recognize Sunrise,
whether it's a control on the form, or a publicly declared variable,
or part of a publicly declared class.
I also tried using single quotes in the expression to be evaluated.
I also tried enclosing the eval in another layer:
Function EvaluateExpression(stExpression As String)
EvaluateExpression = Eval(stExpression)
End Function
Of course, if I go to debug and do
?stExpression
and then put a ? in front of the result, it works just fine!

I could just forget all this and use case statements. However, I
wanted to leave room for a user to add some calculation that didn't
occur to me. Can it be done?


Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kevin Smith | last post by:
I want to evaluate an expression using eval(), but I only want to supply the variable values "on demand." For example, let's say that I want to evaluate 'x+y'. Normally, I would create a...
6
by: Dan | last post by:
I need to be able to execute a command that is defined in a string. In VBScript, I can do it with the Eval function. How can I do it in VB.Net? I need something like: Dim x As Integer...
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
8
by: abhishek | last post by:
>>a,b=3,4 7 Now I want to evaluate y by substituting for the evaluated value of x. eval(y) will try to add "a+b" to 3 and return an error. I could do this, 10 but this becomes unwieldy if I...
8
by: Jeff | last post by:
I'm new to Visual Web 2005 using VB: ....trying to get something like the below to run. Apparently, I need something other than the eval function, but what? Thanks in advance Jeff
10
by: Jeff | last post by:
I guess that I should have explained better (I'm stil new with this, so I may not be asking the questions in the best way) Normally, one would use the simple code: if x>y then something end...
8
by: fredo | last post by:
This question was asked in comp.lang.javascript with no result. In IE5.x and IE6, I want to display an image when the user rolls over a text link. The image does indeed display, but only on the...
8
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - When should I use eval? ----------------------------------------------------------------------- The ` eval() `...
13
by: My Pet Programmer | last post by:
The way I usually set up and work with the XMLHttpRequest to execute server side functions and get results is this: var url = "someurl?params=" + params; var conn = createRequest(); // gets an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.