The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Ranges in conditional structure

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Taron Posted - 04/09/2014 : 11:33:43 AM
Origin Ver. 8.6 b70
Operating System: Windows 7 x64

Hi,

I need help with a little problem I have concerning a Labtalk script.

I want to define a range variable depending on a certain condition.
I tried to do this with the following if clause:



if(directioninc < 0) {
	range rr1a1 = [%H]1!Col(1);
	type "variable < 0";
}	
else {
	range rr1a2 = [%H]1!Col(1);
	type "variable > 0";
};

range rr1b = [%H]1!Col(2);
rr1b = rr1a1;


I do not know why, but for some reason this construct does not work. Everytime I get the error:

Undefined variable: rr1a1

The strange thing is that the if construct seems to work because the "variable > 0" or "variable < 0" is printed every time but somehow the ranges do not get defined, which is the main idea of this part of my script.

Can anyone help me and solve why this does not work?
2   L A T E S T    R E P L I E S    (Newest First)
Taron Posted - 04/10/2014 : 04:07:41 AM
Thanks a lot! I didn't know this. Now my script works nicely!
lkb0221 Posted - 04/09/2014 : 3:17:57 PM
Hi,

This is because the range variable is defined inside the if condition, so Origin consider it as a local variable and thus be deleted once the if section ends.

You can use @global to force the variable be a global variable.
For example:
//
if(directioninc < 0)
{
@global=1;
range rr1a1 = [%H]1!Col(1);
@global=0; // turn it off when done define
type "variable < 0";
}
else ...
//

Zheng
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000