| 2.3.2.2 Substitution NotationLabTalk-Substitution-Notation The substitution of LabTalk variables and expressions occurs routinely in Origin. Since the value of the substituted string is unknown until the statement is actually executed, it's called run-time string substitution. It is also the cornerstone of any repetitive batch operation (import, analysis, graphing and graph export). 
 The substitution notations are preceded with % or $ and are not limited to LabTalk Script only. It also happens in labels in various windows, including axis title, legend, tick labels or regular text, column & cell display format, column & cell formula, etc. When it is found, Origin will replace it with the interpreted string. 
 Types of SubstitutionThere are four types of run-time substitutions:
 ExamplesVarious substitution notations are used in the following script to demonstrate its usage. such as
  %H is a reserved string register for current window name %1, %2 are arguments of macro $(ii,##) is used to convert ii into 2 digit string with zero padding, e.g. 1 will turn into 01 $(ii) is used in wks.col$(ii) to create worksheet column object wks.coln %(1, @WS) is used to create string with 1st's plot's worksheet name
 Please start a new project to try this.
 //define a macro with two argument %1 and %2
define import_plot 
{
	for(ii = %1; ii <=%2 ; ii++) 
	{
		if (!isEmpty(col(A))) newsheet; 
		//create fn$ string variable with concatenated strings
		string fn$=system.path.program$ + "Samples\curve fitting\step$(ii, ##).dat";
		impasc fname:=fn$; 
		delete col(A); 
		if (exist(%H)==2) //if current window type is worksheet
		{
			//set every odd other column as X
			for( jj = 1 ; jj <= wks.ncols ; jj+=2)
			{
				wks.col$(jj).type = 4; //wks.col1 refers to 1st column
			}
		}
	}
	page.active$=1; //activate 1st sheet
	doc -e LB //loop through all sheets
	{
		//plot all columms as scatter with XY column designation
		plotxy iy:=(?,1:end) plot:=202;
		xb.text$="X"; //set X axis title as X
		yl.text$=%(1, @WS); //Set Y axis title as worksheet name
	}
};
//execute the macro with two arguments 1 and 5, 1 and 5 will be passed to %1 and %2
import_plot 1 5; //import step01.dat to step05.dat and plot all dataAs mentioned at the beginning, such substitution notations are used not only in LabTalk Script but also in various places in Origin. E.g.
 |