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
 How to check for arguments in macros/scripts?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

johannes.kastl

Germany
71 Posts

Posted - 02/20/2013 :  08:06:02 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi everyone,

I discovered labtalk macros a while ago, and wanted to use one macro including arguments. As always I wanted to make sure there is an error when no arguments are provided, so the users knows how to use the macro.

The only way I found is rather ugly:

def ArgumentTest {
	string Argument1="%" + "1";
	string Argument2="%" + "2";
	if ("%1" != Argument1$ && "%2" != Argument2$) {
		type "Two Arguments %1 and %2";
	}
	else {
	        type "Some error message";
	}
}


If no argument is provided, %1 is used as literal text %1.

Invoking with no or just one argument triggers the error message:
ArgumentTest Test


Is there a smoother way? How to prevent %1 from being substituted before running the commands?

Origin Ver. and Service Release (Select Help-->About Origin): 8.6.0G SR3
Operating System: WinXP SP3

greg

USA
1378 Posts

Posted - 02/20/2013 :  10:44:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I found this in the LabTalk Help:

Def TypeArgs
{
if (macro.narg != 3)
{
type "Error! You must pass 3 arguments!";
}
else
{
type "The first argument passed was %1.";
type "The second argument passed was %2.";
type "The third argument passed was %3.";
}
}

Go to Top of Page

johannes.kastl

Germany
71 Posts

Posted - 02/21/2013 :  03:00:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Greg,

thanks for the answer, thats a lot smoother.

However, I wonder why I never found that page before. Searching for "labtalk check arguments", "labtalk test for arguments", "labtalk empty arguments" and lots more just came up with the examples on e.g. http://qhwiki.originlab.com/~originla/howto/index.php?title=Tutorial:Advanced_Scripting_using_LabTalk#Defining_a_LabTalk_Script_Macro_Command.

Funny.

Nevertheless, thanks for the help.

Regards,

Johannes
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