Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling Procedure in a Program (.PRG)
Message
From
23/10/2018 14:38:37
 
 
To
23/10/2018 14:00:13
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01662746
Message ID:
01662747
Views:
62
>Respected all,
>
>I have a .prg File , in which I have sequence of procedures I have to carry on one by one to get my desired results. Till Now I have kept all procedures in sequence of one another, but since there are many such procedure (Steps) involved and my .prg has become big and less understandable easily.
>
>I am thinking to put procedures at the end of .prg and Call that procedure step by step so that it may be easily comprehended.
>
>For this I have kept one of such Procedure under PROCEDURE LEFTBOX at the end of my .prg file and calling that procedure using DO Leftbox.
>
>The procedure is generating value for it but when it comes back to the main routine it gives error as variable Boxstartrow not found.
>
>If I declare Boxstartrow as PUBLIC, it works fine.
>
>Will I have to declare all such variables as Public, which I am intending to use in procedure or there is some other way also ?

Don't ever use public variables. They cause far more problems than they solve.

It's not entirely clear what you're doing here, but I think the answer is that you need to declare the variables you need in the main program and then pass them as parameters to the routines that use them. So you'd have something like:
LOCAL BOXSTARTCOLUMN, BOXENDCOLUMN, BOXSTARTROW, BOXENDROW, BOXCOLUMNRANGE
* Add other declarations for variables you need in other of the routines

DO LeftBox WITH BOXSTARTCOLUMN, BOXENDCOLUMN, BOXSTARTROW, BOXENDROW, BOXCOLUMNRANGE

DO abc with ...

DO xyz with ...
You'll also have to modify the routines themselves to accept the parameters, like this:
PROCEDURE LeftBox
LPARAMETERS BOXSTARTCOLUMN, BOXENDCOLUMN, BOXSTARTROW, BOXENDROW, BOXCOLUMNRANGE
 * rest of the code
All that said, this sounds like a candidate for defining a class, where you can make all those variables into properties and then just reference this using This.Whatever.

Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform