Jump to content

Recommended Posts

Posted

hello there,

i was wondering if there's a way to evaluate a string as a boolean

ie: if bool_str then

do something

end if

with bool_str being something like "varibale1 = variable2" or "RS.recordCount = variable" or more complex things

thanks


Posted

Yes, if I understand your question

I remember in C it's

if ( string1 == String2 )
{
allwhatyouwant;
}

In delphi (i think but not sure ...)

if  ( string1 = String2 )
then begin
allwhatyouwant;
end;

The " string1 = string2 " return a boolean value ( true or false )

But you can't do

if ( boolean = string ) then

I hope it's that ... :blushing:

Posted (edited)

that's not what i meant in my question,

what i want is to use a string as the expression for the if statment

suppose i have this string:

Str = "cmbNames.Text = ""saprouzy"""

cmbNames being a comboBox

i want to a function (ie EvaluateSt) to evaluate Str and return a boolean

If EvaluateSt(Str) Then

do bla

end if

Edited by saprouzy
Posted (edited)

EDIT: changed. didnt understand at firet.

Think you want "text1.text.tostring" to return string value from textbox

Edited by dman
Posted

saprouzy, what you want is not possible, but there is workarounds for specific cases.

With your example :

Str = "cmbNames.Text = ""saprouzy"""

you can enumerate the "Controls" collection of the form (with For Each), check if each control's name is the right name, then check if the control's default/specified property has the right value.

Following code is not tested, but it will show the idea :

dim c as control

for each c in <YourForm>.Controls

if c.name = left$(str, instr(str,".")) then

' c is the right control

if c = right$(str, len(str)-instr(str,"=")) then

' retrun true

endif

endif

next

If you want to check other properties than the default one, you'll need to enumerate each possible property (hardcode them)... that's the line in red : I wrote it for the default property ; if you always check the same property, e.g. the "Tag", replace "c" by "c.Tag".

If you want to check multiple properies, you'll need to extract the property from Str, then string compare it with all other properties (predefined as strings too), then check if the property (not in a string) has the right value.

Did you understood me ?

PS 1: all of this is impossible AFAIK with variables (except if you "hardcode" a small subset).

PS 2: you may prefer to use "Object" instead of "Control" (this will allow you to use recordsets)

bye

Posted

what you suggested is interesting, but i guess it only works for simple cases

what i wanted to do is for more complex stuff, for example

Str = "cmbText = SomeFunction(someArg)"

if Str then

do bla

end if

i guess it's impossible :wacko:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...