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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 How to check for arguments in macros/scripts?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
johannes.kastl Posted - 02/20/2013 : 08:06:02 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
johannes.kastl Posted - 02/21/2013 : 03:00:45 AM
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
greg Posted - 02/20/2013 : 10:44:30 AM
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.";
}
}


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000