Jump to content
Macro Express Forums

Goto & Label commands


Recommended Posts

Hi all,

 

Looking for some clarification on the Goto/Label commands.

 

Reading in Macro Express help, it seems that the GOTO command should be used within an IF routine in a macro.

 

Is the GOTO command required to be used within an IF routine only, or can it be used independently to send the Macro back to a previous line (marked with a LABEL) as soon as the GOTO line is reached/activated?

or should I be using a different command?

 

I have a large macro which seems to be having issues with GOTO, where I want the macro to go back to the start after completing its required function.

 

many thanks

Andrew

Link to comment
Share on other sites

Hi Andrew,

 

Although I suppose it would mainly be used with IF routines, Goto can be used anywhere.

 

Here's a simple example to play with:

 

:Start

Text Box Display: Message 1

If Variable %N[1]% Is Greater Than "3"

Goto:Over3

Else

Text Box Display: Message 2

Variable Modify Integer %N[1]%: Increment

End If

Goto:Start

:Over3

Text Box Display: Final message

 

To isolate the problem with your large macro, perhaps you could post the pertinent sections of script. Or, better, post a very small macro that exhibits the same behaviour.

 

--

Terry, East Grinstead, UK

Goto-Demo-Andrew.mex

Link to comment
Share on other sites

Although I suppose it would mainly be used with IF routines, Goto can be used anywhere.

 

Here's a simple example to play with:

 

:Start

Text Box Display: Message 1

If Variable %N[1]% Is Greater Than "3"

Goto:Over3

Else

Text Box Display: Message 2

Variable Modify Integer %N[1]%: Increment

End If

Goto:Start

:Over3

Text Box Display: Final message

--

Terry, East Grinstead, UK

This can be much better written as follows (I know the supplied example was simply to illustrate the use of GoTos, but within professional ranks the use of GoTos is generally very strongly deprecated because it tends to make programs much harder to debug; if you're interested, read up on what Dijkstra (one of my heroes) had to say, and look up spaghetti code. I do not say that GoTos are always bad or wrong, but IMHO their use should be a last resort).

Repeat until %N[1]% is greater than 3
 Text Box Display: Message 1
 Variable Modify Integer %N[1]%: Increment
End Repeat
Text Box Display: Final message

I think this second piece of code is far easier to understand and is much more concise.

Link to comment
Share on other sites

This can be much better written as follows (I know the supplied example was simply to illustrate the use of GoTos, but within professional ranks the use of GoTos is generally very strongly deprecated because it tends to make programs much harder to debug; if you're interested, read up on what Dijkstra (one of my heroes) had to say, and look up spaghetti code. I do not say that GoTos are always bad or wrong, but IMHO their use should be a last resort).

Repeat until %N[1]% is greater than 3
 Text Box Display: Message 1
 Variable Modify Integer %N[1]%: Increment
End Repeat
Text Box Display: Final message

I think this second piece of code is far easier to understand and is much more concise.

 

Agreed. I'm curious to hear why Andrew is using Goto. I'm guessing it's for a similar reason to why I occasionally end up doing so so, when a nested set of IFs and ELSEs scrambles my brain. ;)

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Hi,

 

Many thanks for your replies and direction provided.

 

Having used Macro Express as a great resource for many years with simple macros, I am now creating more complex routines and learning as I progress.

 

I have been trying to use GOTO command to jump forward and backwards within a macro depending on tasks being completed or not (some of these include IF functions).

 

From your comments it looks like I should learn more about variables and intergers to see if the required function can be replicated this way.

 

I will read up and test some senarios and report back if I find a solution.

 

All the best

Andrew

Link to comment
Share on other sites

OK,

 

Think I have found the bug causing issues and have isolated the script below!

 

In the first part of the Macro it is checking if the OUTLOOK "New Item Alerts" window is open.

If not open the macro just keeps restarting (this works fine).

 

The issue comes when the "New Item Alerts" window is open. The macro performs its function by closing this window and completing its task.

 

Only problem is when the full macro has completed I want the macro to redo this part and check if any new alets have arrived, or not.

 

When the macro script below is run for the second time and the "New Item Alerts" window is NOT running, macro acts as if it is!

 

Why is this, does ME have a variable in the background I need to reset, or is there something else I need to do? (there are no other windows running to conflit with the IF test)

 

 

 

<LABEL Name="RESTART"/>

<IF WINDOW Option="\x01" Title="New Item Alerts" Partial="TRUE" Wildcards="FALSE"/>

<WINDOW ACTIVATE Title="New Item Alerts" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>

<DELAY Flags="\x01" Time="0.1"/>

<TEXT TYPE Action="0" Text="<ALTD>c<ALTU>"/>

<MACRO RUN Use_ID="FALSE" Name="2 - CHECK OUTLOOK" ID="-1" Wait="TRUE"/>

<ELSE/>

<GOTO Name="RESTART"/>

<END IF/>

 

 

Many thanks

Andrew

Link to comment
Share on other sites

Update:

 

I setup a test to clarify if the Outlook 2003 "New Message Alerts" window was causing a problem for the macro.

 

It turns out that it is!

 

Test 1: Running the macro to close the "New Message Alerts" window and repeating the macro found ME acting as if the "New Message Alerts" window was still running. The window had previously closed, was NOT running.

 

Test 2: Running the macro as before, but adding a sequence to close and restart Outlook. This acted as a refresh and when the macro was repeated as before it ran correctly. ME did not think the "New Message Alerts" window was running!

 

By adding outlook restart my whole macro runs perfectly now.

 

Can anyone shed some light on how the alert tool works for Outlook 2003, the alert window is triggered by an email rule on arrival of specific type of email?

Is there a process which continues to run after closing the "New Alert" window that conflicts with ME?

 

Although I have fixed the macro, I don't want to be forced into restarting Outlook every time this macro runs?

 

best regards

Andrew

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...