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
 Creating and deleting global variables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cdrozdowski111

USA
247 Posts

Posted - 02/24/2013 :  08:04:37 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 9.0.0 SR1, Win7 64-bit, running in VMware Fusion 5.0.2

Howdy,

I have a question about declaring global variables and deleting them. In the sample code below, I force a variable to be global and test for it's existence. Then I delete it and check for it's existence again. (The code would be in an OGS file making the variable declarations local by default).

Why does the global variable continue to exist after it is deleted?



// Declare local variable
double nMyNum = -5.4321;


// Declare global variable and assign it to local var value
@global=1;
double G_MYNUM = nMyNum;
@global=0;


// Check for existence of global variable - it will evaluate to true
if (exist(G_MYNUM) == 4)
{
	type "It exists before delete";
}


// Delete global variable
del -v G_MYNUM;

// ?!?!? Delete local variable ?!?!?
del -ra G_MYNUM;


// Again, check for existence of global variable - it will evaluate to true again
if (exist(G_MYNUM) == 4)
{
	type "It exists after delete";
}

cdrozdowski111

USA
247 Posts

Posted - 02/24/2013 :  1:10:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I found the issue.

The code:

@global=1;
double G_MYNUM = nMyNum;
@global=0;

creates a session-level variable. Session-level variables can only be deleted in the session scope (which isn't the case if the code is in an OGS file).

If the variable of is declared as a project-level variable:

// Declare project-level variable and assign it to local var value
G_MYNUM = nMyNum;

it can be deleted from within an OGS file.
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