Author |
Topic  |
|
SteffenG
Germany
Posts |
Posted - 03/04/2010 : 03:08:08 AM
|
Origin 8.0G SR6 Operating System: WinXP
Hello all,
since many days I worked at some scripts. Each time I run into problems and Origin crashed instead of running my scripts. I opened two topics here in the forum regarding these issues but there were no solutions for my problems.
Today I found the reason for the problems and crashes. There is a limit in the number of command-lines which one can write inside of an IF-loop. Maybe this is true also for other loop-constructions. I didn't test this. You can test this issue with the following script:
spectra_offset=0; ii=0;
if (spectra_offset!=0){ type $(ii) $(spectra_offset); ii++; } else { type -b; type -c "File is empty - no spectra available!"; }
This script is inside a text button. If one hit the button the script is running. This script with only one instance of the bold written lines is running very well. But if you copy and paste the two bold script lines and step over a limit of 64 copies (128 command lines) than Origin crashes.
One will mention that these code lines should never run because of the if-condition. So it doesn't matter if you step inside of the if construction or not.
Regarding the number of the code lines some tests at my computer show me that comments and empty lines will not count.
As a work around one can put everything inside the if-construction inside of a macro. One can call this macro from the if-construction and there seems to be not such a limit of 128 command lines.
Maybe this issue could be fixed in the next service release.
Regards, Steffen |
|
larry_lan
China
Posts |
Posted - 03/04/2010 : 9:29:26 PM
|
Hi Steffen:
Yes, you are right, this is a LabTalk limitation. As you mentioned, you can write the code in a macro and call it inside the loop. From Origin 8.1, which supports Function, you can also use function instead of macro. Thanks for reporting this.
Larry |
Edited by - larry_lan on 03/04/2010 10:19:01 PM |
 |
|
SteffenG
Germany
Posts |
Posted - 03/05/2010 : 04:20:08 AM
|
Hi Larry,
thanks to know that this is a labtalk limitation. Maybe it would be a could point to add this information to the manual and help files. It took me one week to find out what was the problem.
Another point: Is it right that the main difference between the macro and the function is that a function has a return value?
Regards, Steffen |
 |
|
larry_lan
China
Posts |
Posted - 03/05/2010 : 04:33:14 AM
|
Yes, function has return values and easy to pass parameters. It's similar to other program language. Please see the examples in above link.
Larry |
Edited by - larry_lan on 03/05/2010 04:35:25 AM |
 |
|
greg
USA
1379 Posts |
Posted - 03/30/2010 : 10:54:44 AM
|
The script limitation can be easily missed, but it's in the Help file. Search for "Extending a Statement over Multiple Lines". This is one of those key things to know when you develop code by continually adding lines of code rather than using more recommended approaches : functions, macros and OGS sections. |
 |
|
andrewdsto
Australia
Posts |
Posted - 02/28/2011 : 9:20:35 PM
|
Hi, This is interesting to know, what the limitation is. I too had noticed that there was a problem and was using the call to external macros to run the loops. But its good to know the size of the loop allowed. Thanks |
 |
|
|
Topic  |
|