Como crear variable combinada - Forum

Forum Navigation
You need to log in to create posts and topics.

Como crear variable combinada

Page 1 of 2Next

intento crear una variable combinada y asignarle un valor pero obtengo como resultado "Indefinida" en esa variable si la llamo con un Alertbox para ver que contiene:

SetVar [Cantidad([cont])]    [Cantidad]

Donde:

cont : 1

[Cantidad] : Se ingresa mediante un Input de texto

@gustavo1973, lo que llamas variables combinadas en VisualNEO Web son objetos.
La sintaxis correcta sería así:

CreateEmptyObject [objCantidad]
SetVar [objCantidad([cont])] [cantidad]
AlertBox "Valor:" "[objCantidad([cont])]" ""

Fíjate que no puedes tener un objeto ni un array con el mismo nombre que una variable.
Más información aquí:
https://webhelp.visualneo.com/JSON.html

Vadim has reacted to this post.
Vadim

Buenisimo, ahi me funciono

Puede ese objecto creado almacenar un valor no numerico? un texto?

Puede ese objecto creado almacenar un valor no numerico? un texto?

¡Pues claro! Incluso puede almacenar otro objeto, o un Array... también puedes utilizar objetos bidimensionales.
Hay varios ejemplos relacionados con el plugin neoTable donde se utilizan objetos más complejos.

Good day! I have a similar question.
What this code (VisualNEO Win) should look like in VisualNEO Web?

Loop "1" "30" "[i]"
 If "[RadioGroup[i]]" "=" ""
     AlertBox "Attention!" "Ignored question number [i]. || Please answer..."
 EndIf
EndLoop

 

@vadim:

What this code (VisualNEO Win) should look like in VisualNEO Web?

Let us assume that you created an array of answers like ...

CreateEmptyObject [RadioGroup]
SetVar [RadioGroup(0) ] "Donald"
SetVar [RadioGroup(1) ] "Duck"
SetVar [RadioGroup(2) ] "USA"
SetVar [RadioGroup(3) ] ""
etc. etc.
SetVar [RadioGroup(29) ] "Pinochio"

... then, if you want to check that every array item is present ...

Loop "0" "29" "[i]"
   If "[RadioGroup([i])]" "=" ""
      AlertBox " Attention! " "Ignored question number [i]. || Please answer ..."
   EndIf
EndLoop

 

 

Vadim has reacted to this post.
Vadim

Thank you very much!
It turns out that the Radiogroup variables must be created in advance with an index in brackets. For example, [RadioGroup(1)], [RadioGroup(2)], [RadioGroup(3)]...
So that later they can be used in the cycle Loop [RadioGroup([i])].
I understand correctly?

@vadim:

It turns out that the Radiogroup variables must be created in advance with an index in brackets.
So that later they can be used in the cycle Loop [RadioGroup([i])].
I understand correctly?

I was merely responding to your enquiry about the equivalent of array/compound variables in VisualNEO Win (NeoBook).

With VisualNEO Web, you deal with arrays and reference each item in the array by wrapping it in round brackets.

So yes, you have to create this array using CreateEmptyObject.

However, you do not have to create individual items in advance; but you can setup the items using the same Loop/EndLoop block ... instead of ...

If "[RadioGroup([i])]" "=" ""

... use ...

SetVar [RadioGroup(i)] ""
OR
SetVar [RadioGroup(i)] "--unanswered--"

 

Vadim has reacted to this post.
Vadim

I think it's interesting to mention here that using a bit of JavaScript can be very convenient when using variables whose name is composed from the concatenation of strings or other variable values.
Take a look at this sample:

Loop "1" "30" "[i]"
BeginJS
    if($App["RadioGroup"+$App.i] == ""){
        alert("Attention!" "Ignored question number "+$App.i+" \n Please answer...");
    }
EndJS
EndLoop

So, from JavaScript using $App.myvarwill get the [myvar] NeoScript variable value.
Also this $App["myvar"] or this $App["my"+"var"] will do the same.
And also this:

mystring="var";
$App["my"+mystring]=myvalue;

 

Vadim has reacted to this post.
Vadim

@vadim @gaev @gustavo1973 I have been thinking on this and I think it's possible to reprogram SetVar command so it behave exactly as in VisualNEO Win regarding compound variables.
Will do some experiments and let you know.
Best regards.

Vadim has reacted to this post.
Vadim

@gaev, @luishp, thank you very much!

I have been thinking on this and I think it's possible to reprogram SetVar and GetVar commands so they behave exactly as in VisualNEO Win regarding compound variables.

Oh, it will be great!!

@gaev, @vadim, @gustavo1973 I have created a sample app with neoSetVar and neoGetVar subroutines to allow composed variables. You should use this syntaxis: [myvar(varB)(varC)] instead of [myvar[varB][varC]]
Please test it and let my know if it works as expected.
If so, I'm not sure if I should replace the current SetVar or create a new command.
What do you think?

Thanks!!

FILE UPDATED 2019/05/30

 

Uploaded files:
  • You need to login to have access to uploads.

@luishp:

1) It appears to work well; a good improvement for developers that are not comfortable using JSON/Array objects to store/access related information items.

2) Method of specification - in order to avoid confusing such variables with array/JSON items, instead of [prefix(suffixa)(suffixb)], I suggest one of ...

[prefix+suffixa+suffixb]
[prefix&suffixa&suffixb]
[prefix&&suffixa&&suffixb]
[prefix:suffixa:suffixb]

3) Command name - in order to avoid breaking any existing Apps, I would not combine this into GetVar/SetVar ... best to give it a separate name that indicates that it is a complex specification where the variable name needs to be resolved first ... right now, the only catchy names I can think of are ...

GetCompositVar
GetComplexVar
GetSuperVar
GetSuffixedVar
GetDynamicVar

Funciona perfectamente,

The sample works great!
Will it work in the case of a cycle? (When a variable for a loop position is used inside a compound variable).
For example:

Loop 1 20 [i]
  If [RadioGroup(i)] = ""
    AlertBox "Attention" "Missed question number [i]" ""
  EndIF
EndLoop

 

It seems to me that if it is possible to leave the syntax of VisualNEO Win, it is better to leave it. This will simplify the transition of users from VisualNEO Win to VisualNEO Web.

The ideal option is to leave square brackets for compound variables. If we accept that variables are always in square brackets, then they should remain in square brackets also in compound variables. This syntax will not confuse the user.

 

Hi @vadim,

It should work this way:

Loop 1 20 [i]
  neoGetVar [tempvar] [RadioGroup(i)]
  If [tempvar] != ""
    AlertBox "Attention" "Missed question number [i]" ""
  EndIF
EndLoop

I need to ask Dave for help in order to use brackets as there is no way to use them right now.
I think the new commands should be called:

neoGetCompVar
neoSetCompVar

GetCompVar
SetCompVar

What do you think?

I attach an example. In the example I check - the user answered both questions or not.
1) For some reason, the variable [i] is one more than it should be.
2) Emptiness is apparently interpreted as zero. This prevents the logical condition from being met.
*
I do not see how to attach the file to the message. Made a link:
http://orgpsiholog.com/example/neosetvar.neoapp

I think the new commands should be called:

neoGetCompVar
neoSetCompVar

It seems to me that it is possible without a prefix:

GetCompVar
SetCompVar

(But you know better.)

P.S.: There was an error in my message # 15, I have now replaced the "! =" Sign with the "=" sign.

@vadim please check the attached file.
There was an error in neoGetVar subroutine. I have updated the above sample file.
I have edited and simplified your sample too.

P.S.: There was an error in my message # 15, I have now replaced the "! =" Sign with the "=" sign.

Note that in VisualNEO Web you should use "==" and not "=" as the last one will assign the value instead of comparing it.

Uploaded files:
  • You need to login to have access to uploads.

Luis, thank you very much!
Your example works great!

I just do not understand why the variable [i] at the end has a value one more than it should be.
If I understand correctly, after the end of the cycle, the variable for the position of the cycle should contain the same value as the one on which the cycle should be stopped (the second parameter of the Loop command).

In my example, [i] should contain 2, but contains 3.

@Vadim:

I placed this command just before the EndLoop ...

SetVar "[beforeEndLoop]" "[i]"

... you will then see that [beforeEndLoop] ends up with a value of 2.

This suggests that ...

- the value of [i] is incremented in the EndLoop command
- then, control returns to the Loop command, where it compares [i] with the value in the second parameter; jumps to command after EndLoop if [i] > second parameter value

It is because of javascript's implementations of the for loop ... I tried this example (modified from one in W3Schools) ...

var text = "";
var i;
for (i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
text += "At End of Loop, the number is " + i + "<br>";

document.getElementById("demo").innerHTML = text;

... at the end, it shows 5 (not 4).

This is a good thing when using ExitLoop inside the Loop/EndLoop block ... that way the value 5 (in example above) indicates that the loop was exited because the range was exhausted, while 4 would indicate that it was exited when i was 4.

luishp has reacted to this post.
luishp
Page 1 of 2Next