%Variable%(???)

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

%Variable%(???)

Post by PepsiHog » Wed Dec 26, 2012 2:57 am

This is directed at Marcus. But if you have an answer, please do post.

Marcus,
What purpose does a variable that has not been assigned a value, having a value serve?

Please use a value of %Example% in a macro. The variable being Example.

This causes a person who is writting a long macro to have a HUGE list of let statements, even if the variable is to equal nothing.

let>rgb_1=
let>rgb_2=
let>rgb_3=
let>rgb_4=
let>rgb_5=
let>rgb_6=
let>rgb_7=
let>rgb_8=
let>rgb_9=
let>rgb_10=

I am interested in there being a use for this or not. And what logic it follows that a var not assigned equals something.

However, I have a favor to ask of you.

Will you please with a cherry on top and whatever else you like, maybe add a system variable such as:

Let> Default_value=

So the default value can be set to nothing or whatever the programmer chooses.

I am not speaking of numeric value. That I get.

PepsiHog

>>> I'm always afraid that you or someone else will think I'm having an attitude when I post things like this.
I want to be clear that in no way am I having an attitude. I'm just curious. :)
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Dec 26, 2012 8:39 am

I'm not sure I understand the question.

Sometimes you need to initialise a variable. E.g. a loop counter might need initialising to 0 or some other value before the loop. Or a string that grows would need to be initialised to something - usually an empty string.

Your example initialises the variables to an empty string.

To make that clearer I usually use this format:

Let>newVar={""}

There's no such thing as "nothing".
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Thu Dec 27, 2012 12:17 am

Marcus,

The above examples were to demonstrate setting a string value to "nothing" or an empty string. Both meaning the same. An empty string is technically something, but in my case, I don't usually use empty strings except to later assign a value (not numeric).

Anyway, here is what I was refering to. Lets say you write a macro. No strings have yet to be defined. To check your string you-

mdl>%StringNotDefined%

MS gives a message of %StringNotDefined%. Literally. Maybe you would say that's just to show it's not set yet. But if you use another command it returns the same. For this example let's say you have an array. The array hasn't been defined. Your macro checks to see if it has been.

RegEx>1,StringNotDefined_1,0,Match,nm,0

Because the array returns %StringNotDefined_1% the search for 1 is successful. But the programmer didn't set this value, so it shouldn't be found. This shows that the string has a value of %StringNotDefined_1%. We are not looking for a numeric value. The same is true if you replace 1 with any of the letters in StringNotDefined. And even in the case that you search for %. It finds that twice.

This leads to having to set every variable to an empty string. But in this case it was never defined, and yet the programmer still has to deal with a value.

It's just that when you write a significantly long macro, constantly having to set up strings in the beginning of the program makes an already long macro even longer. What I am saying is, if the string was empty by default it would save a lot of programming and reduce the size of the macro.

So that lead to the above post. I thought you may have a reason for this value. I am curious to learn if there is. But also, as a request, I am suggesting a system variable such as Default_String. That a programmer could set all variables to be empty until otherwise set. Or whatever strikes their fancy.

However, if there is no reason, or it doesn't have to be, then maybe it can be that all strings are empty until defined by the programmer.

Yes, I can hear you now. Well why would you check a string you didn't define? The answer is sometimes variables are built as they are needed. Such as doing this -

if>UserInput=yes
let>StringDefined_%Number%=SomeValue
endif

Doing this is very useful, in many ways.

Depending on the case it may or may not have been assigned a value. Your macro may want to check to see if it has a value of 1, or contains data at all. As it is, a programmer must set all variables, even if they may not be used, to an empty string to avoid problems.(False positives) Yes, they could be set at the moment they become true, but that is still more coding and an even longer macro. As the above example in my first post shows, setting variables to be empty can take up several lines. And that's just one array.

I hope I have been able to explain this well.

Thanks,
PepsiHog

Well after thinking this over, I guess it's the same thing. Whether a system variable or a huge list of variables it still needs to be done. But there's no shame in my game, I like ease of use.

So...... pretty please??
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Thu Dec 27, 2012 11:58 pm

If>%StringNotDefined%=
Do Something
Else
Do Something Else
EndIf

I just use this, then if you need to use the array you can chuck it in there.
FIREFIGHTER

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 28, 2012 10:39 am

You can also use Assigned to see if a variable exists.

If a variable hasn't been assigned then it is a literal. Macro Scheduler is unique in that, by default, you don't need to do anything special to distinguish between a literal and a variable. This helps beginners. So if %variable% is not a variable it is literal string "%variable%".

To change this default behaviour such that %variable% would give nothiing would risk breaking many existing scripts and there will be instances where people meant the literal.

However, I can see the value in an option for the more advanced user, when used in conjunction with VAREXPLICIT which would see any unassigned %var% expressions return nothing.

Though I am not sure if that is what you are asking.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Fri Dec 28, 2012 3:47 pm

@CyberCitizen
Sorry. Interested. But I'm not following what you are saying.

@Marcus

Thank you. Just as you said. An option that would make unassigned variables equal nothing. That would be AWESOME.

I can see what you're saying about breaking macros already made. That wouldn't be good. You are right about that.

That brings me back to this. If a variable has a literal meaning and eguals %variable% how could this be useful in a macro/program?

Ok, I'm just thinking out loud........but maybe it would be useful as a switch. If the var is created then do this. So the var doesn't need to equal anything special. Is that it? My puny little brain.....damn my puny little brain!!! (Sorry, is french allowed here?)

I know JRL knows the answer. (I know you're here, JRL.)

PepsiHog

[edit] - I just thought. When I use variable I am refering to what is also known as a string or literal. Maybe it's the wrong word to use.
Last edited by PepsiHog on Fri Dec 28, 2012 3:53 pm, edited 1 time in total.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Dec 28, 2012 3:53 pm

I would rather have an option to return an error for an unassigned variable.

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

hello

Post by PepsiHog » Fri Dec 28, 2012 4:01 pm

@me_again
You're working against me, man. You're working against me. *Laughing*

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Dec 28, 2012 5:00 pm

@PepsiHog
I'm a Coke guy, what else can I do? :lol:

Seriously though, if you can use ANY variable name without having to think about it, what happens when somewhere later in the program you have a typo in the name of one of your "might or might not be used" variables? You may not realize it until years later when your spacecraft fails to land on the planet Cola.

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Fri Dec 28, 2012 6:12 pm

@me_again

That just goes to show you, Coke IS evil! :lol:

I'm not sure I see your point. Have you ever written such a long macro that you have a list more than a page in length of variables that you had to set to an empty string? Caring about a variable? I'm not sure how you can write a macro without giving thought to variables. Even ones that may or may not be created have a structure within the macro. An error to tell you that a variable is undefined is (in my opinion) pointless. First you may, as Marcus pointed out, want that var to be undefined. Second, if being defined causes your macro to work, then debugging said macro would eliminate the error.

My point is not needing to set the var to an empty string. Which, by doing so, can significantly increase the length of your macro.

Anyway, Marcus got it. And I don't want him to get upset about the continuation of this post.

Don't be evil, drink Pepsi,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Dec 28, 2012 7:33 pm

You could always use a loop:

Code: Select all

Let>k=1
Repeat>k
let>rgb_%k%=
Add>k,1
Until>k>1000

clark5901
Newbie
Posts: 1
Joined: Wed Jan 30, 2013 11:41 am

Post by clark5901 » Wed Jan 30, 2013 11:48 am

Thanks for the nice information in the post...

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Apr 01, 2013 6:36 am

Hi PepsiHog,
How to detect a parameterized variable has been assigned?
In the case, Assigned> won't work.
Let>a_1=123
Let>a_2=456
Let>i=1
Assigned>a_%i%,result
It will tell you it's False but it isn't.

On the other hand, nor can Assigned> tells you it's a null string.
Let>i=3
Assigned>a_%i%,result

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Post by PepsiHog » Sun Apr 14, 2013 5:37 am

@armsys

You could just be agreeing with me or are you asking me?

if you are asking.....

let>a=1
let>parameterized_%a%=This now has a value.

Later, you want to check that var for a value.

let>Temp=parameterized_%a%
assigned>Temp,Result

On a personal note. I don't use Assigned. I just check the string for what I am looking for. Or check if it is equal to nothing. But, six to one, half a dozen to another.

Did this help?
PepsiHog

[edit] - I said "value" for lack of a better term. I was not refering to numerical value. But this can be used that way as well.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sun Apr 14, 2013 7:13 am

Hi PepsiHog,
>Did this help?
Absolutely. I'm interested in knowing how other MS gurus verify if a parameterized variable such as a_%i% has been assigned with a non-null value.
So far there is no satifactory solution to verify if a parameterized variable has been assigned with a value in Macro Scheduler.
However, on the other hand, many Macro Scheduler commands such as SEPARATE> and FINDIMAGEPOS> return parameterized variables.
Anyway, thanks for your thoughtful feedback.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts