Welcome! Log In Create A New Profile

Advanced

Local routines inside procedures

Posted by Ola 
Ola
Local routines inside procedures
January 08, 2011 08:11PM
I would very much like to have the possibility to add local routines inside procedures/functions (like in Clarion CPD). This would save many gotos and/or separate small procedures, which make the code harder to read and maintain.

Ola
[www.pienoismalli.com]
Stefan Bentvelsen
Re: Local routines inside procedures
February 08, 2011 09:49AM
Hi Ola,

I would this also very appriciate !
Ola
Re: Local routines inside procedures
October 25, 2011 11:52AM
I am just wondering, why can't they do this. I wouldn't think it is too difficult?!?!?

best regards
Ola
Ola
Re: Local routines inside procedures
November 07, 2011 03:52PM
Just in case PCS does not understand what I am talking about here, I am referring to a command which is known as "gosub" in Basic and "do" in Clarion...:-)

Even the simpliest home computers had a gosub command already in the 80's...
Carlo Hermus
Re: Local routines inside procedures
November 10, 2011 02:00PM
Ola,

You have GOTO in WinDev.

...code here

GOTO Label


:Label
...code here
Ola
Re: Local routines inside procedures
January 14, 2012 06:15PM
Hi Carlo,

I am aware of the Goto command. I try to avoid it, but use it when necessary. But it is not the same as calling a local routine, which in many languages is done with gosub. Goto continues the code from where it ends, while gosub would return to where it was called from.

Routines can be built using Goto, but the code will be rather awkward, even ugly:

Some code here
CallingPoint = "A"
Goto Subroutine1
ReturnPointA:
And the code continues...

Return //This procedure ends here

Subroutine1:
Do some deed
Switch CallingPoint
  CASE "A": Goto ReturnpointA
  CASE "B": Goto ReturnpointB
END


------------------

There are some workarounds:

Instead of a procedure, create a window, and then you can use the window's local procedures. This is a good, or even a better solution especially when the procedure actually needs a window to ask for parameters and to show progress.

Use global procedures like local routines. This I don't like; it is like shooting a fly with an 88 mm FlaK. If the local subroutine is needed only in its parent process, then putting it in a global procedure unnecessarily breaks the compactness of the code and makes it more difficult to re-use the main process in other programs.

WD's windows have local procedures, so I really wonder why procedures (and Reports!!!) cannot have local routines in a similar way?

Local routines would help make the main code more manageable, readable and maintainable. It could then be divided into logical parts. Routine would also help avoid repeating some pieces of code. Especially it would help break down some long IF and SWITCH structures.

Every self-respecting programming language has a gosub command (or equivalent). Unfortunately Wlanguage does not.

Best regards
Ola
[www.pienoismalli.com]
[www.datamyyra.fi]
Jepotter
Re: Local routines inside procedures
February 08, 2012 04:15PM
Hello Ola,

Maybe I do not understand but would CALL or EXECUTE work for this?

[doc.pcsoft.fr]

[doc.pcsoft.fr]
Ola
Re: Local routines inside procedures
October 23, 2014 03:25PM
It seems that PCSoft is finally introducing this feature in Wx20.

Ola
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: