Execute String Content


I just got stucked trying the following:

I have a Listbox which is filled in a method. The method accepts a string. This string is filled with
sql_string = “data.column(”“id”").StringValue, data.column("“same_value”").StringValue"
In the method I want to use the string as:

This is not working as expected. The line will contain only the string, but I want to have the content of the data.column. Is there a way to “execute” the string?

With my best regards


Perhaps what you are looking for is

sql_string = data.column("id").stringvalue + ", " + data.column("same_value").stringvalue

Hello Wayne,

thank you for your quick reply. Unfortunately this does not help here. Maybe I need to make a little bit better explanation. In the main function I have the following code:

data = Prepare_Fill_CB(CB_Category,"SELECT id, category FROM categories ORDER BY category ASC") Fill_CB_test(CB_Category,data,data.Column("category").StringValue)

The Prepare_Fill_CB method expexts the ComboBox name and an SQLString As String. Inside the method I do the following:

return app.db.SelectSQL(SelectSQL)

and this works. Here I can put a string inside the brackets and it get executed.

The Fill_CB_test method expects the name of the ComboBox, the data as RowSet and the comand to fill the rowset as a string. Inside the method it does the follwowing:

if data <> Nil Then While not data.AfterLastRow MessageBox(Fill_Comand) ComboBox1.AddRow(Fill_Comand) ListBox1.AddRow(Fill_Comand) PopupMenu1.AddRow(Fill_Comand) data.MoveToNextRow Wend end if

(This is for testing purposes for the moment, only.)

Anyway, if I follow your suggestion, it will repeat only the first database entry in the Listbox, ComboBox, etc., as the Fill_Comand is executed, before it was handeld over to the method and the method can not change it, while iterating through the database rows. If I change the above statement to:


It will repeat in the Listbox, Combobox, etc. only the String “data.Column(“category”).StringValue” but does not fill it with the database entries.

What I’m looking for is to path this string and get it executed inside the method. Hope this is now a little bit more clear.

I’m trying to follow your post, but I’m not understanding the whole idea. Instead of describing the technologies you think you need, could you tell us what the desired functionality is supposed to be?

It sort of sounds like you want to create a reusable load method for these controls, but I’m not sure. Do you have an example project that shows what you’re up to or could you describe the desired effect and not the Xojo code?

[quote=481206:@Robert Kahl]
What I’m looking for is to path this string and get it executed inside the method. Hope this is now a little bit more clear.[/quote]

you cannot do this in Xojo
you cant execute the contents of a string as if its code

And the reason you cannot do this is in the manner you described is because Xojo is a compiled language, not interpreted at runtime the way something like say PHP.

There are still some things that can be done with introspection or other techniques. So as Tim requested, perhaps it would be better to describe the ultimate goal better rather than the originally proposed solution – which can’t be done as Norman has stated.

Sorry I assumed you were trying to run SQL that you were putting into a string which is fine. If you want to create xojo code in a string and run it then that gets more complicated as others have already said Xojo is compiled and not an interpreted language. There is xojo script for that though. But it won’t do what you described above as it doesn’t have access to your programs objects and variables.

Thank you for your help. What I want to do is to not always need to repeat the

if data <> nil then While not data.afterlastrow ... wend end if

and some other settings to set up the listboxes in the program. So I wanted to put it in a method which is flexible enough to fill more then one listbox with different database content. Therefore I wanted to give the Information for the listbox.addrow() instruction as a parameter to the method and then put it between the brackets.

If I am following right what you want to do, then instead of passing a string like “data.column(”“same_value”").StringValue". pass just the column name itself such as “category” and so your call to Fill_CB_test is more like this:


then Fill_CB_test becomes more like this:

if data <> Nil Then While not data.AfterLastRow dim Fill_Value as String = data.Field(Fill_Command).StringValue MessageBox(Fill_Value) ComboBox1.AddRow(Fill_Value) ListBox1.AddRow(Fill_Value) PopupMenu1.AddRow(Fill_Value) data.MoveToNextRow Wend end if

A recordset’s Field() method can take a string with the column name, so if I understand the request right, I think this will achieve your end goal. Personally, I would rename the final Fill_CB_Test() argument from Fill_Command to something like Column_Name, as it now serves a slight different purpose.

Thank you - of cause this is the solution.

And if I have - like for a listbox - sometimes one, anothertime more parameters I could use an array for the parameter and loop through all array entries to fill up the Fill_Value String.