Post Reply 
[Programming] Treat like an adress, not like a number
12-02-2017, 12:03 AM
Post: #1
[Programming] Treat like an adress, not like a number
I'm doing a little program, but I have to deal with several different numbers of input, it will all depend on the first user input(condTot).

If the user choose 5, for example, it will ask them several questions about each one of those 5 elements.

I could do a "case/if", for each one, with a limit, but I wanted to do better.

So I did this loop, It takes the user input(condTot) and then it will create a list os inputs, asking questions about each one of those 5 elements.

But there is a problem with this aproach, when I put: L9(TEMP1,1), it will append the value of "L9(TEMP1,1)", not the adress, and then, when i call it back with the input, the value of formVar element will be like:

{0,[0]{20,20,1}} //What i get
Not:
{L9(TEMP1,1),[0]{20,20,1}} //What I want

And when it goes inside of INPUT, of course it will give me trouble...

Is there any way of avoiding that? Or is there any way to make the input do what I want?? A flexible way of doing INPUT.

Code:
FOR TEMP0 FROM 1 TO condTot DO
  TEMP1:=2+TEMP0;
  formVar:=append(formVar,{{L9(TEMP1,1),[0],{20,20,1}}, {L9(TEMP1,2),[0],{70,20,1}}});
  formTit:=append(formTit,{"X Cond: "+TEMP0, "Y Cond: "+TEMP0});
END;

INPUT(formVar,"TEST", formTit, "EI,EI");

The rest of the code

Thank you for reading, and I would apreciate if you could help me Smile
Find all posts by this user
Quote this message in a reply
12-02-2017, 07:58 AM
Post: #2
RE: [Programming] Treat like an adress, not like a number
I hope that using [] instead of {} for indices using lists will help you.
Find all posts by this user
Quote this message in a reply
12-02-2017, 09:21 AM
Post: #3
RE: [Programming] Treat like an adress, not like a number
(12-02-2017 12:03 AM)alexandrehos Wrote:  
Code:
FOR TEMP0 FROM 1 TO condTot DO
  TEMP1:=2+TEMP0;
  formVar:=append(formVar,{{L9(TEMP1,1),[0],{20,20,1}}, {L9(TEMP1,2),[0],{70,20,1}}});
  formTit:=append(formTit,{"X Cond: "+TEMP0, "Y Cond: "+TEMP0});
END;

INPUT(formVar,"TEST", formTit, "EI,EI");

If I understand well you are building a list of couples of input values with formVar. What's not clear for me is what you expect to get with the final INPUT. Do you expect to get all couples of input values on the same input screen?
Find all posts by this user
Quote this message in a reply
12-02-2017, 11:46 AM
Post: #4
RE: [Programming] Treat like an adress, not like a number
As far as I know, you can't pass a variable to a function by reference.

What you can do is:

* return a value and assign it to the variable when returning from the function

* if you wanted to pass more than one variable by reference then return a list of values and pick the return values out of the list upon returning

* make sure the variable that you want to pass to the function is global pass its name to the function in a string, then within the function, append ":=value" to the string and then do EXPR(yourString)
Find all posts by this user
Quote this message in a reply
12-02-2017, 01:46 PM
Post: #5
RE: [Programming] Treat like an adress, not like a number
(12-02-2017 07:58 AM)Arno K Wrote:  I hope that using [] instead of {} for indices using lists will help you.
Nope :/
When you make an input, you give it "lists", like this:

Code:
INPUT(
{
{condTot,[0],{42,20,0}}, {flechaSN,0,{90,10,0}},
{xComum,[0],{20,20,1}}, {yComum,[0],{70,20,1}},
{rComum,[0],{20,20,2}}, {tipComum,{"MACICO","FILAMENTADO","GEMINADO","BESSEL"},{70,25,2}}
},
"Informações gerais",
{
"Qtde de condutores:","Flecha",
"X Comum", "Y Comum",
"R Comum", "Tipo Comum"
},
{
"Quantos condutores no total?","Tem flecha?",
"Posição da maioria", "Altura da maioria",
"Raio da maioria", "Tipo da maioria"
}
);

This will give me a form like this:
[Image: 1UbnYvp.png]

But at the end of this, you will see that is not exactly lists Sad

So guys, before I move on, I did some changes on my program, now I'm using the EXPR() function, like grsbanks suggested Smile
First I make a list, in a form of a string, and when I give it to the INPUT function, I give it using the EXPR function, like this:

Code:

formVar:="{";
FOR TEMP0 FROM 1 TO condTot DO
TEMP1:=2+TEMP0;
IF TEMP0==condTot THEN
//This is to just to know if it is the lant item, if so, it will not have a comma
formVar:=formVar+"{L9("+TEMP1+",1),[0],{20,20,"+TEMP0+"}}, {L9("+TEMP1+",2),[0],{70,20,"+TEMP0+"}}}";
ELSE
formVar:=formVar+"{L9("+TEMP1+",1),[0],{20,20,"+TEMP0+"}}, {L9("+TEMP1+",2),[0],{70,20,"+TEMP0+"}},";
END;
formTit:=append(formTit,"X Cond "+TEMP0+":", "Y Cond "+TEMP0+":");
END;
//formVar will be a string and formTit a list
//Now the input:
INPUT(
{
EXPR(formVar) //To take the string and give it like a list
},
"TEST",
{
formTit
}
);

And, in an ideal world, the program would understand like this:
Code:

/I got this after printing, copying and pasting the exact output from formVar and formTit, and give them to a separated INPUT().
INPUT(
{{L9(3,1),[0],{20,20,1}}, {L9(3,2),[0],{70,20,1}},{L9(4,1),[0],{20,20,2}}, {L9(4,2),[0],{70,20,2}},{L9(5,1),[0],{20,20,3}}, {L9(5,2),[0],{70,20,3}},{L9(6,1),[0],{20,20,4}}, {L9(6,2),[0],{70,20,4}},{L9(7,1),[0],{20,20,5}}, {L9(7,2),[0],{70,20,5}}}
,"TEST",
{"X Cond 1:", "Y Cond 1:", "X Cond 2:", "Y Cond 2:", "X Cond 3:", "Y Cond 3:", "X Cond 4:", "Y Cond 4:", "X Cond 5:", "Y Cond 5:"});

And my INPUT would look like this:
[Image: exORI8W.png]

But, of course, the world is not that simple so, I got "Error: Invalid input".

(12-02-2017 09:21 AM)Didier Lachieze Wrote:  Do you expect to get all couples of input values on the same input screen?
So, that's what I want, if the user enters 3, it will 6 questions on the next INPUT, for entering 4, 8 inputs in the INPUT screen, and so on Wink

grsbanks, L9 is global, formVar and formTit are local.

After that, I had to dig a little further, and I did this, I gave something that I know that it will work, I extracted the list of inputs, and gave it back, but now in a list.

Code:

test:={ //the input list
{condTot,[0],{42,20,0}}, {flechaSN,0,{90,10,0}},
{xComum,[0],{20,20,1}}, {yComum,[0],{70,20,1}},
{rComum,[0],{20,20,2}}, {tipComum,tipos,{70,25,2}}
};
INPUT(
test, //the list
"Informações gerais"
);

And I got "Error: Invalid input", so, the thing we give to the INPUT function that looks like a list, is not exactly a list :/

Thank you guys again for the help
The rest of the code
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)