×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Shared common variables

Shared common variables

Shared common variables

(OP)
Hi everyone,

I have just started to develop once again in qbasic and for the love of everything I can not remember how to share a variable between modules

Before the main function runs I have declared

Common shared TerminalNumber as string

But I can not seem to access it from another function

Example

Public sub PrintTerminalNumber
Print TerminalNumber
End sub

How do I allow the printTerminalNumber sub access to the TerminalNumber?

I even have tried to declare it like

public sub PrintTermialNumber (byval termID string)

And the. Run call PrintTerminalNumber (TerminalNumber) but it print a blank entry

I would appreciate any help or example
Code on this


Thanks

Andy

RE: Shared common variables

What compiler are you using? Original old DOS QBasic or QB64?

RE: Shared common variables

(OP)
I'm using PDS 7.1 as well as vbdos

RE: Shared common variables

I tried it only in QB64.
Passing data to subroutines as parameters or via shared variables works like in this example:

mainpgm.bas

CODE

DIM a AS STRING
DIM SHARED b AS STRING
COMMON SHARED c AS STRING

CLS

a = "foo"
b = "bar"
c = "baz"
PRINT "Main program:"
PRINT "a = " + a
PRINT "b = " + b
PRINT "c = " + c

CALL sub1(a$)

CALL sub2(a$)

END
'------------ subroutine -----------
SUB sub1 (x$)
    PRINT "* calling SUB1:"
    'a is not normally visible in SUB1, it must be SHARED
    SHARED a$
    PRINT "  a = " + a$
    PRINT "  b = " + b$
    PRINT "  c = " + c$
    PRINT "  x = " + x$
    PRINT "**"
END SUB

'--------- included module ---------
'$INCLUDE: 'module01.BM' 

module01.bm

CODE

SUB sub2 (x$)
    PRINT "* calling SUB2 from the module:"
    'a is not normally visible in SUB2, it must be SHARED
    SHARED a$
    PRINT "  a = " + a$
    PRINT "  b = " + b$
    PRINT "  c = " + c$
    PRINT "  x = " + x$
    PRINT "**"
END SUB 

Output of mainpgm.exe:

RE: Shared common variables

(OP)
I think I just spotted what I need to do

SHARED a$

would i include that like this


SHARED a$


CODE --> BASIC

Public sub PrintTerminalNumber
SHARED TerminalNumber 
Print TerminalNumber
End sub 

RE: Shared common variables

then your issue seems to be resolved

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close