Thread: global variables in qbasic

  1. #1
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116

    global variables in qbasic

    hey im making a game in qbasic and i want to know if i can make global variables so all the SUBs have access to them so i dont have to pass like 50 variables every call. thanks in advance for the help.
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  2. #2
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    Illusion and reality become impartiality and confidence.

  3. #3
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    i went to that site and posted on the board but i didnt see it on there afterwards. also how do i reply to what someone else posted there? i dont like those kinds of boards very much....
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Welcome to cprogramming.com. We use C and C++ here.
    Away.

  5. #5
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    u forgot c#....

    but i figured someone would know qbasic or be able to help me. at least this is a programming board and not, say, a cooking board. and the board is game programming, not specific to any language.

    just for future reference, this is my 100th post.
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  6. #6
    Then again, the game programming board is under the General Programming Boards category, not C(++, #) Programming Boards section.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    42
    Let's be nice to him.

    Now I have very little knowledge of QBasic. Just enough for my QBasic class in school. . But I believe if you declare variables outside a SUB then it is global.

    Like this:
    Code:
    CLS
    StringOne$ = "This is string one."
    END
    I'm thinking that StringOne$ is global. Or is it not?
    Sigh, nothing ever works the first try.

    Register Linux User #314127

  8. #8
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    well if i declare them as constants they work, but otherwise they dont. thats a step in the right direction, but i need them to not be constant. any other ideas?
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  9. #9
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    sorry for bumping this up, but i couldnt edit (its been more than 1440 minutes)
    i finally figured out how to make the global though, and i wanted every one to know,

    DIM SHARED variables(x)

    then just store the vars in there. i use constants to reference certain cells (ie i have CONST STRENGTH = 1; CONST DEFENSE = 2; et al, and then if i need to see their strength i just do PRINT variables(STRENGTH))

    thanks for the help though (or lack there of, in some cases )
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  10. #10
    Registered User
    Join Date
    Sep 2003
    Posts
    11
    Originally posted by Geo-Fry
    [B]sorry for bumping this up, but i couldnt edit (its been more than 1440 minutes)
    i finally figured out how to make the global though, and i wanted every one to know,

    DIM SHARED variables(x)

    then just store the vars in there. i use constants to reference certain cells (ie i have CONST STRENGTH = 1; CONST DEFENSE = 2; et al, and then if i need to see their strength i just do PRINT variables(STRENGTH))
    That's a rather inefficient method if you just want to store individual variables.

    The correct syntax for global variables is:

    Code:
    COMMON global1, global2, somevar3, somevar4
    Just plug in your global variables in a COMMON statement at the top of the file.

    Hope that helps!

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    COMMON is only used if you are sharing variables between
    QBasic programs. Since QB progs have a 64KB limit and are all in the small memory model, I can't see much use for it myself. COMMON helps in VBDOS so that your forms know about certain variables. I normally use the DIM SHARED or CONST to declare global variables.

    QB is not nearly as elegant in dealing with multiple file or multiple module programs as C/C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global variables.
    By vapanchamukhi in forum C Programming
    Replies: 5
    Last Post: 09-15-2008, 05:02 AM
  2. Replies: 5
    Last Post: 08-06-2008, 09:59 AM
  3. global variables - okay sometimes...?
    By MadHatter in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2003, 04:23 PM
  4. global variables
    By rdnjr in forum Linux Programming
    Replies: 0
    Last Post: 01-07-2003, 10:28 AM
  5. Global variables? Bad! Yes, but to what extent?
    By Boksha in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2002, 04:37 PM