How to get rid of automatic output with varput?

When I use the function VARPUT to assign a variable name in a loop, each time a variable name is assigned a "1" is displayed as output. For example:

for i(1,3,1);
    varput(i,"var" $+ ntos(i));
endfor;
           1.000 
           1.000 
           1.000 

However, I have a loop that uses varput many times, generating an annoying amount of "1"'s...is there anyway to stop varput from generating this output automatically? Thanks

2 Answers



1



accepted

The 1's that you are seeing printed after running the code:

for i(1,3,1);
   varput(i,"var" $+ ntos(i));
endfor;

are the return values from each call to varput. The documentation states that varput will return a 1 if the function is successful and a 0 if it is not. If the return is not assigned to any variable, then it is an implicit print statement.

Therefore we can prevent the printing of this return value by assigning the return to a variable, like this:

for i(1,3,1);
   //Assign 1's to 'ret' instead of printing them
   ret = varput(i,"var" $+ ntos(i));
endfor;

For functions that only return one value, this is generally just fine. However, sometimes there will be a function that returns 3,4 or more variables. In these cases (and the singe return case above), you can use the call keyword. The call keyword, tells GAUSS to discard the returns from the function. Simply place call in front of the function call like this:

for i(1,3,1);
   //'call' tells GAUSS to throw away any returns
   //notice there is no equals sign used
   call varput(i,"var" $+ ntos(i));
endfor;

aptech

1,393


0



@aptech Excellent! This worked very well thank you.

Your Answer


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy