saprouzy Posted June 25, 2005 Posted June 25, 2005 hello there,i was wondering if there's a way to evaluate a string as a booleanie: if bool_str then do something end ifwith bool_str being something like "varibale1 = variable2" or "RS.recordCount = variable" or more complex thingsthanks
Indigo2005 Posted June 25, 2005 Posted June 25, 2005 Yes, if I understand your questionI remember in C it's if ( string1 == String2 ){allwhatyouwant;}In delphi (i think but not sure ...)if ( string1 = String2 )then beginallwhatyouwant;end;The " string1 = string2 " return a boolean value ( true or false )But you can't do if ( boolean = string ) thenI hope it's that ...
saprouzy Posted June 25, 2005 Author Posted June 25, 2005 (edited) that's not what i meant in my question, what i want is to use a string as the expression for the if statmentsuppose i have this string:Str = "cmbNames.Text = ""saprouzy""" cmbNames being a comboBoxi want to a function (ie EvaluateSt) to evaluate Str and return a boolean If EvaluateSt(Str) Then do bla end if Edited June 25, 2005 by saprouzy
Indigo2005 Posted June 25, 2005 Posted June 25, 2005 oh ok !I don't think you can ...you have to slip your string.cmbNames.Text is a caracteristic of a component, you can't use it as a string !
saprouzy Posted June 25, 2005 Author Posted June 25, 2005 cmbNames.Text is a caracteristic of a component, you can't use it as a string !<{POST_SNAPBACK}>that's exactly what am trying to do.. hehe
dman Posted June 25, 2005 Posted June 25, 2005 (edited) EDIT: changed. didnt understand at firet.Think you want "text1.text.tostring" to return string value from textbox Edited June 25, 2005 by dman
Delprat Posted June 25, 2005 Posted June 25, 2005 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 controlfor 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 endifnextIf 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
saprouzy Posted June 27, 2005 Author Posted June 27, 2005 what you suggested is interesting, but i guess it only works for simple caseswhat i wanted to do is for more complex stuff, for exampleStr = "cmbText = SomeFunction(someArg)"if Str then do blaend ifi guess it's impossible
saprouzy Posted June 27, 2005 Author Posted June 27, 2005 is there a way to get the list of declared variables?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now