Instance variables not usable for variable conditions?

My workflow consists of going through a folder with one or more files, but the macro could trigger every time a file is added, so I choose instance variables so things don't get messy if the macro triggers twice.

I go through the current files (For Each File...) and read the file into an instance text variable.

However, the next step requires "IF (instance variable) CONTAINS the string ""Nord" : ,"

This if/then check doesn't work when it is an instance variable?!

As soon as I removed "instance" from every variable involved, just to check, the check for the string DOES work.

Am I missing something, or can I just not search an instance variable like that?

(Also, noob question, how do I post those beautiful macro screenshots like many others do?)

You certainly can:

Instance Test.kmmacros (5.0 KB)

Image

Change the text in the first action so it does/doesn't match and you'll see the "If..." works fine.

From your description you could even use a "local" variable, unless your macro is calling subroutines or macros that also need to access those values.

Regardless, if it fails with instance variables but works with globals it is likely a "scoping" issue. But it's difficult to say without seeing the macro itself.

Not noob at all!

You'll find instructions for this at How to Post/Upload your Macros and Scripts

As @Nige_S notes, Instance variables work fine in conditions, so something else is going on.

It is likely that a better solution to your problem is to use the Semaphore Lock action at the start of your macro so the macro deals with each file one at a time.

Also, be careful that the macro itself does not add files to the folder that could trigger further calls to the macro.

Thanks for the help!

I revised my entire list of variables in the macro and then it worked, so it was my mistake in naming the variables.

I've got more things than that, but I guess that's for another topic :smile: Cheers!

1 Like