Is there something similar as EVALUATE(Field1)?

Version I posted above works in desktop apps, or here’s a web app version:

[code] dim myField as WebTextField
dim whichFieldToGet as string = window1.WebTextField1.text

	myField=WebTextField(WebPage1.ControlWithName(whichFieldToGet))
	MsgBox myField.text[/code]

[quote=312867:@Neil Burkholder]Using your xojo script example with a dictionary you would do this:

[code]
Dim Field1, Result1 As String
Field1 = “Apple”
Dim expression as String
expression = “Field1”

Dim Dict as new dictionary
Dict(“Field1”) = Field1
Result1 = Dict.Value(expression)
msgbox Result1
[/code][/quote]
In actual fact, Field1 does not exist at all. I had indicated to try to tell you that Field1 value is “Apple” for better understanding.

[code]Dim Result1 As String
Dim expression as String
expression = “Field1”

Dim Dict as new dictionary
Dict(“Field1”) = ?
Result1 = Dict.Value(expression)
msgbox Result1[/code]

I do not know what should be placed in the Question mark.

Public Function AlvinEvaluate(DesiredField as string) as string dim myField as TextField for i as integer = 0 to self.ControlCount - 1 if window1.Control(i).Name=DesiredField then myField=TextField(self.Control(i)) return myField.text end if next End Function

The above method in a desktop app would let you write your code like this to display “Apple” in your example:

msgbox AlvinEvaluate(“f1”)

[quote=312870:@Seth Ober]Version I posted above works in desktop apps, or here’s a web app version:

[code] dim myField as WebTextField
dim whichFieldToGet as string = window1.WebTextField1.text

	myField=WebTextField(WebPage1.ControlWithName(whichFieldToGet))
	MsgBox myField.text[/code][/quote]

Hello Seth, thanks for your great effort. I had worked out a sample WebApp based on your methods but I am still getting syntax error. I would appreciate if you could take a look on it.link text

If Field1 does not exist, it can’t have a value to be extracted. (No apples at all!)

Did you mean it does not exist initially but is created during run time? How does field1 get its unknown value? I think we’re missing some key information about what field1 represents.

Neil, in the example he just posted, (“Field1” “Field2” etc.) are actually properties on the web page.

I’ve got to go into a series of meetings now, so I’ll leave it to others… I haven’t used introspection in a web app–does it work there? If so, that’s probably the direction he’s heading in now…

Alvin, please confirm or correct the following as it will help us to help you. Based on the example you sent me, it looks like:

  1. You’re looking for a solution that would work in a web app.
  2. The “fields” are actually properties on the web page.

[quote=312880:@Neil Burkholder]If Field1 does not exist, it can’t have a value to be extracted. (No apples at all!)

Did you mean it does not exist initially but is created during run time? How does field1 get its unknown value? I think we’re missing some key information about what field1 represents.[/quote]
Hello Neil, are you able to take a look at this sample app for better understanding?

One more thought before I have to run: If the ‘fields’ are actually properties on the web page, and their names are known while building the app, you can easily load their values into a dictionary, as suggested by several others earlier. The values could either be loaded into the dictionary once when the app runs, or, if the property values will change over time, load them into the dictionary right when you need to get the particularl value…

Or heck, if they’re properties defined when you’re building the app, you could just use a SELECT CASE statement.

[quote=312883:@Seth Ober]One more thought before I have to run: If the ‘fields’ are actually properties on the web page, and their names are known while building the app, you can easily load their values into a dictionary, as suggested by several others earlier. The values could either be loaded into the dictionary once when the app runs, or, if the property values will change over time, load them into the dictionary right when you need to get the particularl value…

Or heck, if they’re properties defined when you’re building the app, you could just use a SELECT CASE statement.[/quote]
This is just an example, in actual fact, it’s not from property and control. The String is input by user during runtime.

[quote=312881:@Seth Ober]Neil, in the example he just posted, (“Field1” “Field2” etc.) are actually properties on the web page.

I’ve got to go into a series of meetings now, so I’ll leave it to others… I haven’t used introspection in a web app–does it work there? If so, that’s probably the direction he’s heading in now…

Alvin, please confirm or correct the following as it will help us to help you. Based on the example you sent me, it looks like:

  1. You’re looking for a solution that would work in a web app.
  2. The “fields” are actually properties on the web page.[/quote]
    Hello Seth, yes it is an WebApp. The String is input by user during runtime.

You can’t access a property using ControlWithName. Replace the code in your shown event with the code below. You really need to use a dictionary.

Dim s() As String = Split("Field1, Field2, Field3, Field4, Field5", ",")
		
Dim Dict as new Dictionary
Dict.Value("Field1") = Field1
Dict.Value("Field2") = Field2
Dict.Value("Field3") = Field3
Dict.Value("Field4") = Field4
Dict.Value("Field5") = Field5
		
dim myField as WebTextField 
dim whichFieldToGet as string = s(0)
'myField=WebTextField(Self.ControlWithName(whichFieldToGet))
'MsgBox myField.text

MsgBox dict.Value(whichFieldToGet)

This will not work as “Field1” string is entered by user at runtime.

Looked at your example, are you sure you’re not looking for a Control Set?

Sorry to be the bearer of bad news, but unless you put in some effort and give a good description of what you want to do and how you set it up (and not have people trying to guess all the time, even basic things like “is it desktop or web?”) you are simply wasting everyones time.

People here (not me) are very helpful, but this is ridiculous.

It sounds like you are lacking the basic concepts. One of the things that almost every app does is read user input.

Here is a working example. Change the text in any of the fields. Change the string of fields to be returned. See the results in the list box. Play around with it and try to grasp the basics so we can help you better. As Tim suggested a control set would be an even better way to accomplish this.

[quote=312900:@Neil Burkholder]It sounds like you are lacking the basic concepts. One of the things that almost every app does is read user input.

Here is a working example. Change the text in any of the fields. Change the string of fields to be returned. See the results in the list box. Play around with it and try to grasp the basics so we can help you better. As Tim suggested a control set would be an even better way to accomplish this.[/quote]
As mentioned, Field1 to Field5 are not controls. If It does exist, I will be able to use Seth’s method to locate the values:-

Public Function AlvinEvaluate(DesiredField as string) as string dim myField as TextField for i as integer = 0 to self.ControlCount - 1 if window1.Control(i).Name=DesiredField then myField=TextField(self.Control(i)) return myField.text end if next End Function
By removing the Field controls in your sample webapp, it will be bricked. Anyway I greatly appreciated your effort trying to help me out but that is still not what I am trying to achieve.

Are you referring to Evaluate() as in Excel and VBA ? https://msdn.microsoft.com/en-us/library/office/aa223886(v=office.11).aspx ?

Looks to me very much like a dictionary.

You still haven’t said how the user will enter the text at runtime. The most common way is via a control.
Do you have a thought reading helmet… (I don’t)?

Of course! That is the method for collecting the user input.

I can’t write your app for you, if you don’t say what you want!

Based on the documentation I linked to, I believe this works close to the Excel function.

Evaluate is a property of the Session object :

Evaluate as Dictionary

In Session open :

Evaluate = New Dictionary

To set a value :

Evaluate.Value("Field1") = "Apple"

To get a value :

MsgBox Evaluate.Value("Field1")

Since it is a property, the proper way to call it from a WebPage is

MsgBox Session.Evaluate.Value("Field1")

If you want the same values to be shared with all sessions, attach Evaluate to a Module as Global and initialize it in App.Open.

@Michel Bujardet

That will cause a keynotfound exception if the value is not first set. I already gave him a similar answer and the response was: [quote=312872:@Alvin Lim]In actual fact, Field1 does not exist at all… I do not know what should be placed in the Question mark. (To set the value of field1)[/quote]