#1 2015-06-23 23:54:42

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Program flow and SplitStr

Hello,

There is something I can't get because I am too used to classes and OO, it's the program flow. I have seen this and I can not understand (I have put many Log commands to check the type of data returned) :

1/ when I do a SplitStr following the example provided in the help file, for example from inside a Button's code module, I get an array in return
2/ but when I use an App Builder function (not a JavaScript one) that returns a String (String used in a Http code module after a call to that function) and even if I check if it is really a String and even if I check it's content, I can't get an Array after SplitStr

splitstr.png

On the image you can check that :
Line 3 : check if the returned variable is a String
Line 4 : the returned variable is a String
Line 5 : the content of the variable is "societe2;societe1"
Line 6, 7 and 8 speak by themselves

Please, do you see what I am doing the wrong way ? Many thanks

Last edited by svanneste (2015-06-24 00:08:10)

Offline

#2 2015-06-24 00:25:42

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Program flow and SplitStr

Edit: I have found a workaround by inserting a StrReplace inside the Http code module. So I think this does force any casting to a real String ?
strreplace.png

And this does work only by replacing any character inside the source string. Not only the separator.

Last edited by svanneste (2015-06-24 00:26:52)

Offline

#3 2015-06-24 08:08:46

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

Re: Program flow and SplitStr

Hello Samuel,

Trying to reproduce the error I can't do it, because I do not understand very well what you mean when talking about "App Builder function which return an string", then I only can try the "button click way", and this apparently works like expected (see the code below). So please Samuel, if you can provide me with a little app sample I really appreciate it and I will investigate the problem.

SetVar "[MyVar]" "societe2;societe1" "String"
SplitStr "[MyVar]" ";" "[MyArray]"
VarIsArray "[MyArray]" "[Result]"

// true
Log "[Result]"

Online

#4 2015-06-24 11:12:53

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Program flow and SplitStr

Hello David,
I have prepared an example if you would like to test it

Many thanks

Last edited by svanneste (2015-06-24 14:55:16)

Offline

#5 2015-06-24 12:30:21

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

Re: Program flow and SplitStr

Hello Samuel,

Thanks very much for the sample. Certainly the problem is related with how App Builder compile the app code. The program compile first the app views/controls, then the app events, and then the user functions. Since the app views/controls are compiled before the user functions, then the variable "Retour" do not exists for the app views/controls and this cause the problem in our specific case.

What we can do is to set the "Retour" variable before call the user function which use it:

SetVar "[Retour]" "" "String"
DecodeS "[rTemp]"

Try it and post here whatever question Samuel.

Online

#6 2015-06-24 12:46:45

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Program flow and SplitStr

Hello David,

I do thank you for your quick reply which clears many things and helps a lot. To summarize and check if I well understood, could we say that :
"defining the variable inside the parent code module and before a call to the function, makes that variable a Global variable and not only a Reference to that variable" ?

Offline

#7 2015-06-24 13:05:14

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

Re: Program flow and SplitStr

Hello Samuel,

In fact we play with global variables anyway: the problem here is the order in which the variable "Retour" are set. Since the user functions are compiled after the app views/controls, when App Builder translate the "split" action to the appropiate Javascript code, they don't know nothing about the "Retour" variable and the final Javascript code do not produce our expected results.

By set the "Retour" variable before call the user function (no matter if we set the variable in the "Ready" app event, or the "Show" app view event, or just before call the user function) when App Builder translate the "split" action can view that the "Retour" variable exists, and then the final Javascript code produced our expected results. We can view the differences in the below codes:

This is the final "split" function Javascript code if we do not set the "Retour" variable before call the user function:

$rootScope.aTemp = ""+$rootScope.Retour+"".split(";");

This is the final "split" function Javascript code if we set the "Retour" variable before call the user function:

$rootScope.aTemp = $rootScope.Retour.split(";");

We can see that, because App Builder do not recognize the "Retour" variable when translate the "split" action, they take the variable as an string, and this do not produce our desired results. On the contrary, the second code show to us how we deal directly with the variable "Retour" as a variable, not an string, and in this case the "split" function produces the expected results.

Online

#8 2015-06-24 13:13:51

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Program flow and SplitStr

I due you a lot of tapas and beers too wink

Offline

#9 2015-06-24 14:03:03

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

Re: Program flow and SplitStr

Hello Samuel,

svanneste wrote:

I due you a lot of tapas and beers too wink

Thanks! But I need to apologize because something is wrong in my above explanation of the problem. Certainly the order in which the variables are set matter, however, this is not the case of our issue Samuel. So what happend here? Certainly the translation of the "SplitStr" action is not like we expect when the "Retour" variable is not set, however, and, since the "split" is not executed until we click the button, the produced Javascript code can work.

What happend? Taking a more deep view, I can want to try how the "split" Javascript function respond if we want to write something like this code:

SetVar "[A]" "Samuel" "String"
SplitStr "[A],David" "," "[MyArray]"
VarIsArray "[MyArray]" "[Result]"

AlertBox "[Result]" "info"

By my surprise the "[Result]" variable store "false" here too. And the problem is the same that you found in your code. Apparently the "split" Javascript function cannot deal with a Javascript like this:

$rootScope.aTemp = ""+$rootScope.Retour+"".split(";");

Or this other:

$rootScope.MyArray = ""+$rootScope.A+",David".split(",");

Certainly I cannot understand why the above code is not valid, because cannot view something wrong. But the truth is the code do not work and I can fix the problem by change how the "SplitStr" action is translated into Javascript. Now you can see that your app sample (even if you do not set the "Retour" variable before call the user function) work like you expected, and the same for my above code, also works like we expected.

Then maybe I deserves a cold beer, but not for my other first answer... but for this one. You can now update your App Builder copy now Samuel. Sorry for waste your time, but my first impression is more or less logic, because I expect the "split" function is working properly.

The order in which we set the app variables certainly can affect, but not in this particular case.

Thanks for your patience Samuel!

Online

#10 2015-06-24 15:27:09

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

Re: Program flow and SplitStr

Hello again,

Follow the rabbit I found the same problem in other actions like "SubStr", "StrLen" and some others (the program history refer it all) and then I fix the problem and upload an updated release of App Builder. Thanks for the report Samuel, because this problem neccesary appear sooner or later.

Online

#11 2015-06-24 15:37:30

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Program flow and SplitStr

Hello David,
There is something else I have seen: when you want to log the content of a variable which holds an array length, you get a program exception.
But this doesn't mean that the ArrayLength command is not working, it is only the fact that we can not print it in the logs. For example : you can put the value inside an Input field.

Thanks a lot for all the good work you do smile

Offline

#12 2015-06-24 15:47:37

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

Re: Program flow and SplitStr

Hello Samuel,

What I need to investigate is how to deal with objects and also arrays when log to the program console. Certainly we can log an Array without problems in the Firefox console, for example. But for some reason the App Builder debugger console do not output correctly Arrays nor objects, just strings.

But in my case the program do not produce any exception, just that we log some "rare" characters to the console, but not an exception.

What is your Windows version Samuel? On the other hand, I think that output Arrays and objects cannot be too much complex, then I want to try right now for with a possible way.

Online

#13 2015-06-24 15:51:14

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Program flow and SplitStr

Hello David,

David wrote:

What is your Windows version ?

It is Windows 8.1 Pro 64 bits.

If you need an example, I would be glad to provide one based on the one of this morning.

Offline

#14 2015-06-24 15:57:33

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

Re: Program flow and SplitStr

Hello,

David wrote:

What is your Windows version ?

Samuel wrote:

It is Windows 8.1 Pro 64 bits.

If you need an example, I would be glad to provide one based on the one of this morning.


Thanks for the information Samuel. Maybe the exception appear in Win64: I only try here in Win32. Anyway, App Builder is now updated and we can use Arrays variables with the Log action. If you like try it and tell me if they also work in your Windows version Samuel.

Online

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.