What causes Sub routine not to return when finished

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

What causes Sub routine not to return when finished

Post by kpassaur » Sat Dec 08, 2007 11:42 am

I have a very long script that parses data. When it it finds all the data it works fine. When it finds a piece of data it writes it to a text file. When there is an error reading the data it is suppose to write an error line in the text file, which it does.

Once this process is complete it exits the sub routine that parses the data and then it reads and displays the data. This works fine when all data to be parsed exists. The difficulty is that when there is an error parsing the text although it writes the error line, and continues to process the data correctly once it gets to the end of the subroutine it passes right pass the end of the sub and does not return to the next line. I have spent two days cycling though the code and cannot find what it causing this. So, I am looking for what would cause the end of a Sub Routine to be ignored. I think that knowing all the reasons will help me.

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

Post by Marcus Tettmar » Sat Dec 08, 2007 12:15 pm

No reasons I can think of other than some logic which branches out of the subroutine - maybe a dodgy If statement or unintentional Goto or something? Would help to see the code.
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
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Dec 08, 2007 3:49 pm

Really need to see the script.

But you may see the problem yourself if you look at the log file. Using Single Step with BreakPoints while observing the WatchList, and using the Log file, are the two best tools you have to diagnose the cause.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Finding the error

Post by kpassaur » Sat Dec 08, 2007 5:35 pm

Thanks guys, I have been stepping through it and placing a Message Modal box to stop it as I keep an eye on the watch list, I sort of have to as it has 800 lines and a half a dozen loops in it that read text files. I have not tried looking at a log file, which I guess is the next step. One thing I wish though is that MS would have in their editor a way of changing background color on Sub Routines. it sure would make it easier to figure out where they start and stop.

Just an idea

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Finding the error

Post by jpuziano » Sat Dec 08, 2007 7:27 pm

Hi kpassaur,
kpassaur wrote:One thing I wish though is that MS would have in their editor a way of changing background color on Sub Routines. it sure would make it easier to figure out where they start and stop.

Just an idea
That is an interesting idea, though since it is tecnically possible to write a subroutine inside a subroutines inside a... on and on... the background coloring would have to handle that too. Still an interesting idea...

"Code Folding" would also be useful as you could fold up subroutines, if statement blocks, etc., to see more of what's happening at one level, then unfold sections as desired, unfold all, etc. I think this may be on the wish list, I've heard it mentioned before.

Notepad++ also has a great "bookmarks" feature, you just click the mouse pointer to the right of the line number to place a bookmark (a yellow dot) by a line of code and as you move through a big script, you can easily find that line again by watching for the yellow dot. You can also use a menu item or hot key to go to Previous Bookmark, Next Bookmark, very handy when you're working with a huge script.

Marcus, if Code Folding and Bookmarks features aren't on the Advanced Editor Enhancement Wish List, please add... thanks.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Watching sub routines

Post by kpassaur » Sat Dec 08, 2007 8:34 pm

I never throught of the folder idea and that would work well. I like the idea of the colors even though you could have a sub routine inside a another one. The color would still have a start and stop color. There are smarter people me that can come up with a better idea I'm sure. Like yours with the folders.

But what I do know is that what I am working on now has 300 lines in a sub routine with plenty of sub routines inside of it and it is difficult to find the problem with it.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Dec 08, 2007 10:03 pm

What's wrong with blank lines to isolate the subroutine and indented text to tell you what's inside of it? There are already menu items in the Advanced Editor under Edit, "Block Indent" and "Block Un-Indent". Or, as you're typing once you've indented a line, hitting return will start the next line at the previous line's indent position.

Code: Select all

Previous code

SRT>MySub
    Let>something=0
    Let>SomethingElse=1
    If>ICantLook=something
      Let>ICantLook=SomethingElse
    EndIf
END>MySub

More code

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