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
 StringArray isn't created
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

luismramirezr

Brazil
7 Posts

Posted - 04/10/2016 :  10:25:42 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2015
Windows 10

Hi,

I'm running an ogs script after a file import via the run command in the Import Wizard.

In the first lines, a StringArray is created, give some values (Sample 1, Sample 2, etc.), then ask for the real sample names:


//Declare variables to be used
	bookname$ = "DLS";
	wksname$ = layer.name$;
	axislang$ = "English";
	xname$ = "Size";
	yname$ = "Intensity";
	y2name$ = "Volume";
	y3name$ = "Number";
	samples = 1;
	reads = 3;
	
	//Creates Samples name Array
	StringArray names;
	names.Add("Sample 1"); //Add temporary data
	

	//Use GetN dialog to collect data
	getn (Samples) samples	(Reads per sample) reads	(Workbook name) bookname$	(Axis Language) axislang$	(DLS Import);
	
	//Ask for each Sample Name
	names.SetSize(samples);	//Set StringArray size to samples quantity
	//Add "Sample 1", "Sample 2", etc to show in getn dialog
	loop(ii,1,samples){
		names.SetAt(ii, "Sample $(ii)")
	}
	//Ask user to input sample name
	loop(ii,1,samples){
		samplename$ = names.GetAt(ii)$;//temporary var to store sample name
		getn (Sample $(ii) Name)	samplename$	(Input Sample Names);
		names.SetAt(ii,samplename$);//store sample name to stringarray
	}


The problem is that the StringArray isn't created.

If before running the script I create the StringArray in the command window, the script runs perfectly. Otherwise, it gives a lot of errors because de string array wasn't created. After running the script, I can create the array and run the script again and it will run fine. It doesn't matter if I ran the script or not, I must create the array in the command window in order for the script to run.

If copy and paste the above script in the command window, it runs fine. However, if the script is exec from the run command, it gives error.

After run in command window, if I restart Origin and run the script via the Import Wizard or run command, it gives error again, because the string array wasn't created.

Why I can't create the string array inside the ogs script file?

Thank you.

cpyang

USA
1406 Posts

Posted - 04/10/2016 :  11:48:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ogs section is a scope, so when exit the scope, all the local variables are gone, so you need to indicate global variables,

See

http://www.originlab.com/doc/Quick-Help/Global-Constants


CP
Go to Top of Page

luismramirezr

Brazil
7 Posts

Posted - 04/13/2016 :  10:53:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

ogs section is a scope, so when exit the scope, all the local variables are gone, so you need to indicate global variables,

See

http://www.originlab.com/doc/Quick-Help/Global-Constants


CP





Thank you. I used the Origin.ini example and it worked. However, if I give the script to someone else, they will have to do the same thing.

So, this solved in part my problem. I would really like how to define the stringArray in the ogs script file so I don't have to configure the Origin.ini
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