PDA

View Full Version : EVal function in Excel VBA



pannai
03-15-2007, 02:02 AM
Hi
I want to know if Eval function available in Excel VBA?

I want to evaluate values like below
st= "0>=15 or 0>=10"


Thanks

moa
03-15-2007, 04:09 AM
Check out the Evaluate function.

What are you expecting your example to evalute to? As it stands it won't work.

Norie
03-15-2007, 11:14 AM
Why do you need a function?

What exactly should that evaluate to?

mdmackillop
03-15-2007, 11:49 AM
Sub eval()
Dim st As Boolean

st = 0 >= 15 Or 0 >= 10
MsgBox st

st = 20 >= 15 Or 0 >= 10
MsgBox st

End Sub

pannai
03-15-2007, 09:18 PM
Hi
Actualy the expression is not a direct value. I am building the expression by checking various conditions and create the expression as string value.

for e.g, after various validations, my expression will be like below

ep="0>15 or 0>10"

now I want to execute the above expression,

if (ep)
{
do something
}
else
{
do otherthing
}

since ep is a string, it gives error in "if". for this scenario VBScript has Eval function which will evaluate the string expression and return the value.
But VBA doesn't have Eval function.

mdmackillop
03-16-2007, 01:18 AM
Sub eval()
Dim st As String

st = "=or(0 >= 15, 0 >= 10)"
MsgBox Evaluate(st)

st = "=or(0 >= 15, 20 >= 10)"
MsgBox Evaluate(st)
End Sub