Common Statement (AREV Specific)
At 19 APR 2000 04:07:35PM Rick Lewis wrote:
I am having a problem using a Common statement in a subroutine. I get an error - 'Attempt to use Common variables when COMMON not defined.'
I then used the code fragment at the bottom of page 54 in the R/BASIC manual in a test routine and I get the same reult! What am I missing?
Help please!
At 19 APR 2000 07:02PM Warren wrote:
COMMON statements need to before the variables are used in the program. The called SUBROUTINE needs to have matching common statements after which the variables can be used.
Example:
progid=CALLINGPROG
COMMON A,B,C
A=variable A'
PRINT 'This is CALLINGPROG'
CALL EXTERNALSUB
PRINT A
*
progid=EXTERNALSUB
SUBROUTINE EXTERNALSUB
COMMON A,B,C
PRINT 'This is EXTERNALSUB'
PRINT A
A=has been changed'
RETURN
At 20 APR 2000 09:20AM Rick Lewis wrote:
Warren,
Many thanks.
Simple, but not obvious!!!!!!!!!
Rick
At 20 APR 2000 10:33AM Rick Lewis wrote:
Warren, or anyone else.
Not so simple!
Here is subroutine_1:
line 1 COMMON IC,LOG_NO
line 185 LOG_NO='
Here is subroutine_2, EXECUTED by subroutine_1 at line 200:
line 1 COMMON IC,LOG_NO
Both compile fine but when I run subroutine_2 it breaks at line 185 with Msg "Attempt to use COMMON variable when COMMON has not been defined"
What is wrong?
Rick
At 20 APR 2000 10:48AM [url=http://www.sprezzatura.com" onMouseOver=window.status=Click here to visit our web site?';return(true)]The Sprezzatura Group[/url] wrote:
You must CALL the subroutine not EXECUTE it. EXECUTE loads a new TCL level and runs the program so it sets up a new memory space which is not aware of the memory that is being used by sub 1.
Your example would be better served as
Subroutine Sub1
Common IC, LogNo
LogNo=12
IC='
Call Sub2
Return
Subroutine Sub2
Common IC, LogNo
LogNo -= 10
Return
World Leaders in all things RevSoft
At 20 APR 2000 11:22AM Warren wrote:
The CALLed subroutine must be cataloged also (well, in 3.1x it doesn't HAVE to be as the RBasic runtime engine will as where the object code is, but that is an RPITA in production).
One could always use named commons, which allow more flexibility but eat up string/variable space in memory. There's no such thing as free lunch.
At 20 APR 2000 11:49AM [url=http://www.sprezzatura.com" onMouseOver=window.status=Click here to visit our web site?';return(true)]The Sprezzatura Group[/url] wrote:
We don't know - there's this little soup kitchen at the corner of Grammercy and Lex that seems to do it. Do you know something we don't?
World Leaders in all things RevSoft
At 20 APR 2000 11:04PM Rick Lewis wrote:
Warren,
Both subroutines are cataloged! Not running on a run-time version. Any other thoughts?
What's an RPITA?
Rick
At 21 APR 2000 11:07AM Warren wrote:
Hmmm, every soup kitchen I've been to I've had to pay dearly for the meal one way or another.
I guess you wonky Brits have higher standards of cleanliness or stronger stomachs than us Yanks.
At 24 APR 2000 06:41PM Eric Emu wrote:
In our country there's a famous folk song "Waltzing Matilda"
"Once a jolly swagman cramped by a billabong…."