Passing an Arithmetic Operator as a variable 
Author Message
 Passing an Arithmetic Operator as a variable

Hi all

sorry if this is a no-brainer - I just can't get my head around it.

I want to pass an arithmetic operator into a function as a variable, and
then use it in an expression.  e.g.:

------------------------------

Function Test(Criteria, Operator)
'e.g. of args:  Criteria = 3, Operator = ">"

Dim SomeOtherCriteria
Dim Expression

SomeOtherCriteria = 4

Expression = Criteria & Operator & SomeOtherCriteria

If (Expression) Then
    .... do whatever
End If

End Function

------------------

Not surprisingly, the whole expression gets turned into a string and is not
evaluated.  Is there any way do doing what I'm trying to do?

Specifically, I have a table with fields for Operator (e.g. ">"), and Date
(e.g. "Today" (which gets resolved with Now())), and I want to evaluate
wether a file's DateLastModified property is > Today (for example), but the
operator and date criteria will be different for each record.

Any ideas?  Help very much appreciated.

Fiona Conner



Thu, 06 Sep 2001 03:00:00 GMT  
 Passing an Arithmetic Operator as a variable
Take a look at MS Scripting Control. It gives you want you want and much
more.

--
Cludio Avolio Rodrigues
IBM - IT Specialist

Quote:

>Hi all

>sorry if this is a no-brainer - I just can't get my head around it.

>I want to pass an arithmetic operator into a function as a variable, and
>then use it in an expression.  e.g.:

>------------------------------

>Function Test(Criteria, Operator)
>'e.g. of args:  Criteria = 3, Operator = ">"

>Dim SomeOtherCriteria
>Dim Expression

>SomeOtherCriteria = 4

>Expression = Criteria & Operator & SomeOtherCriteria

>If (Expression) Then
>    .... do whatever
>End If

>End Function

>------------------

>Not surprisingly, the whole expression gets turned into a string and is not
>evaluated.  Is there any way do doing what I'm trying to do?

>Specifically, I have a table with fields for Operator (e.g. ">"), and Date
>(e.g. "Today" (which gets resolved with Now())), and I want to evaluate
>wether a file's DateLastModified property is > Today (for example), but the
>operator and date criteria will be different for each record.

>Any ideas?  Help very much appreciated.

>Fiona Conner



Thu, 06 Sep 2001 03:00:00 GMT  
 Passing an Arithmetic Operator as a variable
Thanks, I took a look and there is indeed an Eval function - great.

I can't get it to evaluate dates when the operator is a string though.
e.g.:

cntlScript.Eval(now() & operator & (now() + 1))

returns a syntax error, whereas:

cntlScript.Eval(now() > (now() + 1))

doesn't.

Any further ideas/pointers in the right direction greatly appreciated.

Fiona.

Quote:

>Take a look at MS Scripting Control. It gives you want you want and much
>more.

>--



Thu, 06 Sep 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Overriding Arithmetic Operators (help!)

2. Variable of Datatype Operator

3. Variable of Operator Datatype

4. Can operators be variables??

5. passing javascript variable into asp variable using vbscript

6. Pass client script variable to server script variable

7. passing date variable in select statment of recordset variable

8. passing operators to functions

9. Decalring variables as operators/operands ?

10. Logical Operators and Variables

11. pass operators to an expression

12. Possible bug in VB double-precision arithmetic/comparison operators?

 

 
Powered by phpBB® Forum Software