Variable in the Eval function (1 Viewer)

SunWuKung

Registered User.
Local time
Today, 10:57
Joined
Jun 21, 2001
Messages
172
Could somebody help me with the Eval function?
I have a string that I store in a variable. I would like this string to be evaluated to true or false, but I always get an error message so now I am totally lost how Eval function might work.

TestValue="ReportRequest"

When I write: ? Eval(TestValue="ReportRequest") I get it evaluated to -1. So far so good.

But if I have the string stored in a variable like StringToEval="TestValue='ReportRequest'"

? Eval (StringToEval) gives me the following error message:
Can't find the name 'TestValue' you entered into the expression.

Could somebody tell me how to evaluate this variable (like StringtoEval) that contains a string with a variable?

Many thanks.
SWK
 

charityg

Registered User.
Local time
Today, 10:57
Joined
Apr 17, 2001
Messages
634
Is this what you are trying to do?
If you run this, it should return false, because TestValue="This". If you assign the variant TestValue="This" to stringtoeval, you will return true.


Dim stringtoeval As Variant
Dim TestValue As String
Dim result As Boolean
TestValue = "This"
stringtoeval = TestValue = "That"
If stringtoeval = True Then
MsgBox "True"
Else
MsgBox "False"
End If
 

SunWuKung

Registered User.
Local time
Today, 10:57
Joined
Jun 21, 2001
Messages
172
Sorry,
I didn't explain my case fully.
I have a ValidationRule and a CurrentValue. I must run ValidationRule on CurrentValue and that should return true or false. I think I could justify why this validation is done in this way instead of the usual way, but that would be a longer story.

I tried to have ValidationRule in the form of a regular expression and than run it like Regexp(CurrentValue, ValidationRule) but the free module I found for regular expressions seemed cripled, so I quit that. If somebody knows where to find a good free solution for regular expressions please let me know.

Than I thought that ValidationRules could be strings containing code and I could run that code on CurrentValue.
So a ValidationRule could be anything like these:
1.(CurrentValue="ReportRequest") or (CurrentValue="AddUser")
2.(Int(CurrentValue)=CurrentValue) and ((CurrentValue>0) and (CurrentValue<11))

I would than call a function like this:

ValidationRule="(CurrentValue='ReportRequest') or (CurrentValue='AddUser')"
CurrentValue="ReportRequest"
Validate (ValidationRule, CurrentValue)

This would run the ValidationRule on CurrentValue and returnt true or false.

The way I thought I would do it is simply:

Public Function Validate (ValidationRule as String, CurrentValue as String)
Validate=Eval(ValidationRule)
End Function

but it doesn't work. It gives me the error message: "can't find the name 'CurrentValue' you entered in the expression."
Any thoughts why is it happening and how could I make it work?

Thanks.

SWK
 

Users who are viewing this thread

Top Bottom