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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Ranges in conditional structure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Taron

United Kingdom
12 Posts

Posted - 04/09/2014 :  11:33:43 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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?

Edited by - Taron on 04/09/2014 11:34:10 AM

lkb0221

China
497 Posts

Posted - 04/09/2014 :  3:17:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - lkb0221 on 04/09/2014 3:19:04 PM
Go to Top of Page

Taron

United Kingdom
12 Posts

Posted - 04/10/2014 :  04:07:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot! I didn't know this. Now my script works nicely!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000