#1 2015-05-24 19:30:05

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

load array with LoadVariables action ?

Hello again,
I try to load an array with LoadVariables action, but I´m not successfull. i.e. variables.txt contains a line lcodes=DE,EN,ES,IT but this is not accepted as a array. Do I have to change something or is this not possible.
Thanks in advance
Walter

Offline

#2 2015-05-24 19:54:13

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: load array with LoadVariables action ?

Hello Walter,

"LoadVariables" currently not support Arrays, sorry, but it's a good idea. Stay tunned Walter.

Offline

#3 2015-05-24 21:13:38

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: load array with LoadVariables action ?

Hello again,

Finally I add a new "SplitStr" action which we can use to split an string into substrings in an Array variable.

That is, we can do something like this:

SplitStr "Red,Green,Blue" "," "[Result]"

The "[Result]" variable is an Array which contains the elements: "Red", "Green" and "Blue" in this case.

We can use the separator what we wanted, then the bellow code works too:

SplitStr "Red|Green|Blue" "|" "[Result]"

Also, the "LoadVariables" and "ParseVariables" actions support now Array variable definitions. What we can do it's something like this:

a=Hey!
b=How are
c=you?
d=|Red|Green|Blue

In the above case the "[d]" variable is loaded as an Array with the elements "Red", "Green" and "Blue".

The separator "|" is now mandatory and, as we can see, the variable value must start with the same char: "|".

Then you can prepare a file like this Walter:

lcodes=|DE|EN|ES|IT

However, note one thing more. If you want to access programaticaly to the "[lcodes]" variable, you need to use the "ParseVariables" action and not "LoadVariables".

In fact we can use "LoadVariables" too, but, since these actions are executed asynchronously, only "ParseVariables" (we already have the file contents) can allow us to access the variables right after the action is executed.

Remember the two includes app samples: "LoadVars" and "ParseVars" and note the differences.

Offline

#4 2015-05-24 21:58:55

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Re: load array with LoadVariables action ?

David,
many,many thanks! Your work is incredible and Appbuilder and my enthusiasm for it is growing every hour!
kind regards,
Walter

Offline

#5 2015-05-25 10:19:10

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Re: load array with LoadVariables action ?

Hello David,
I believe, I still missunderstand something: Now I want read a local file (!)  with ParseVariables action. Immedeatly after doing this i have a alert action for controlling the results. But I get always a undefinded - like with LoadVariables.

//load config.txt
ParseVariables "app/files/config.INI"
Alert "" "[loaded];[lcode1]" ""

Thanks for your help

Offline

#6 2015-05-25 13:54:13

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: load array with LoadVariables action ?

Hello Walter,

The "ParseVariables" action doesn't expect an URL, but a text ready to be parsed, for example, we can write something like this:

ParseVariables "Name=Peter\nLastName=Smith"

AlertBox "[Name] [LastName]" "info"

The "LoadVariables" action yes, expect an URL, but we cannot write something like this:

LoadVariables "app/files/config.ini"

AlertBox "[Name] [LastName]" "info"

The point is that "LoadVariables" is executed asynchronously and then requires some time in order to made the appropiate HTTP request, wait for the response, and then parse the received response text.

If we want to use the loaded variables inside an "Html" control this is not a problem, because in literally milliseconds the variables are loaded an appear into the "Html" control like we can expected.

If we want to play with the loaded variables from our app code, we need a way to assert that the variables are already loaded. In this case the recomendation is the use of the "ParseVariables" action.

However, and since "ParseVariables" expect a text to be parsed, we need the help of the "HttpClient" control. The "HttpClient" made the config URL request and inform to us when they are ready.

In few words Walter, we need to use the "HttpClient" control because they can retrieve our config file text, but, most important, because they inform us when the response text is ready.

Once the "HttpClient" control retrieve the config file text, then yes, we can use the "ParseVariables" action and just after their execution we can play with the defined variables without the previous "problems".

I recommend you to review the "ParseVars" app sample. As you can see, in that sample we use an "HttpClient" control to retrieve the variables definition file (our config file) and then wait for the "Success" event.

Is in the "HttpClient" "Success" event when we use the "ParseVariables" action. After that point the variables are availables to be used; before that point the variables are not availables or "undefined".

Hope you understand the points, but don't hesitate to post here your questions.

Offline

#7 2015-08-05 11:01:05

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Re: load array with LoadVariables action ?

Hello David,

I still have a lot of trouble with this stuff - depending on the browser I use and depending where files are hosted. I try to explain:

1. I always speek of a WebApp

2. With IE everything runs fine, local in AppBuilder Debugmode as well as online. Chrome and Firefox run fine local as well!

3. I still use LoadVariables to get some initial vars out of 2 INI files > no problem in IE and mostly in Chrome

4. If I change something in  these files  IE accepts it immediatly, Chrome and Firefox donn´t . although I pressed F5 different times and I empty the cache manually ...

5. I checked the ParseVars sample different times made some test in my app, also using HTTPexecute. BUT the thing is with HttpExecute action I stop the script, all script actions behind HttpExecute will not be executed.

6. So my question is, if there is a possibilty to start i.e a function "loadthis" in the show event of an view and WAIT for the end of the function before continuing  the show event script. For example with a while which is waiting for a response var of the function

7. As far as I understand now the show event script of a view is first read totally and then executed?

8 And last but not least: Do different browsers handle the SetOption and GetOption different? Do they use different webspace? I wrote a own temporary log function which uses SetOption for the log entries. And get different resuklt using IE and/or Chrome/Firefox. confusing!

Thanks for your help

Walter

Offline

#8 2015-08-05 14:45:05

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: load array with LoadVariables action ?

Hello Walter,

Various things to consider here.

4. If I change something in  these files  IE accepts it immediatly, Chrome and Firefox donn´t . although I pressed F5 different times and I empty the cache manually ...

I test right now in Internet Explorer, Firefox and Chrome and works like expected. If I load a file with two variables "a" and "b" I can use "LoadVariables" or "ParseVariables" and then access such variables. If then I change the file and add a new "c" variable, when I use again the refered actions, there is no problem to get the value of the new added variable.

If we are talking of files included by the app, remember that you can edit the original file, but the app have their own copy of the file! If the argument for the "LoadVariable" action is an remote URL (a remote file) then this must work like expected if you edit the remote file, however, remember "LoadVariables" is not the best way load remote files, because we have no feedback.

"LoadVariables" is mainly intended to load variables for an HTML template, that is, the content of an HTML control. We can use in other scenarios too (for my above test I did so) but it's not recomended, since "LoadVariables" do not offer any feedback about their success or error. This action is also intented to work with local (app files) because these files always exists and we can expect a more or less response from the app server.

5. I checked the ParseVars sample different times made some test in my app, also using HTTPexecute. BUT the thing is with HttpExecute action I stop the script, all script actions behind HttpExecute will not be executed.

Something wrong in your script? Because, in fact, for remote files (not app files) the "ParseVariables" is the way instead of "LoadVariables", and, in order to use this action we need the help of an HTTP Client control, like the sample you mention does. I try right now with the "ParseVars" samples and try to modify the remote variables file and all works like expected Walter.

Yes, the "ParseVariables" action can be used to get variables not only to be shown in an HTML content control, but also to use in other possible places, however, we need to take care about the flow of our app. As you know, all the actions are executed asynchronously, that is, be can't expect the variables are ready just after execute the "HttpExecute" action, we need to wait for the "Success" or "Error" events of the HTTP Client control, and use the HTTP Client response as the argument for the "ParseVariables" action.

Then we need to think in that before count with the variables: we can't use the variables until the HTTP Client control "Success" event and the "ParseVariables" call, and we also need to prepare some scenario for a posible "Error" event. Both scenarios depend on what kind of thing we try to do, I just can say at this time that both "LoadVariables" and "ParseVariables" actions works here in all the browser I test, then maybe you have some problem with your script. Maybe you can send me or prepare a sample to try to reproduce the problem?

6. So my question is, if there is a possibilty to start i.e a function "loadthis" in the show event of an view and WAIT for the end of the function before continuing  the show event script. For example with a while which is waiting for a response var of the function

No. I think there is not a way to do such thing Walter. Every action are asynchronously executed. However this not meant we can't do the things, just that we need to think about how to do what we need in an asynchronous way. Then, if you want to execute "something" when the "ParseVariables" end their work, why don't prepare an app function with the "something" stuff and call to that function just after "ParseVariables" in the HTTP Client control "Success" event?

Supose we have two app functions named "GetVariables" and "ProcessVariables". Then our app view "Show" event can look something like this:

GetVariables

1º We call "GetVariables" and that function basically call the "HttpExecute" action to retrieve the remote variables. There is not more stuff in the app view "Show" event.

2º Once the "HttpExecute" is called we wait for the "Success" event of the HTTP Client control. In that event, we use the "ParseVariables" action (using the "[HttpClient1.Response]" variable as argument) and inmediatelly after call to "ProcessVariables".

That's all. We no need to wait for some action execution in the "Show" event, instead of that we "start" the process for retrieving the remote variables file and process the variables when they are retrieved.

7. As far as I understand now the show event script of a view is first read totally and then executed?

I am not sure if understand well, but this and all events and pieces of code are executed following the action's sequence.

8 And last but not least: Do different browsers handle the SetOption and GetOption different? Do they use different webspace? I wrote a own temporary log function which uses SetOption for the log entries. And get different resuklt using IE and/or Chrome/Firefox. confusing!

"SetOption" relies in the "LocalStorage" of every browser. In principle they must work in a similar way. It's just an space to save pairs of keys and values for our apps, then this keys and values must be the same in every browser if we save the same for the keys and values couples. There is no differences in how App Builder deal with this in different browsers Walter.

Hope this all can help you in some manner, but, remember to post here (or in a new thread) whatever you wanted.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.