Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple basic query (I think)

0 views
Skip to first unread message

Paul Young

unread,
Apr 13, 2001, 3:34:36 AM4/13/01
to
Hello all

help wanted I am learning qbasic
I am trying to create variables dependent on a input.
For example If I input G=3
I would like to create variables
q1
q2 &
q3
If I input G=5
I would like to create variables
q1
q2
q3
q4 &
q5

How can this be done


Tom Lake

unread,
Apr 13, 2001, 9:21:34 AM4/13/01
to
> help wanted I am learning qbasic
> I am trying to create variables dependent on a input.
> For example If I input G=3
> I would like to create variables
> q1
> q2 &
> q3
> If I input G=5
> I would like to create variables
> q1
> q2
> q3
> q4 &
> q5

You have to use an array:

INPUT "Enter the number of variables to be created: ", G
DIM q(1 TO G)

then to refer to a particular variable (let's use 3 for an example) do this:

PRINT q(3)

or A = q(3) + 5

To print a list of all the variables, do this:

FOR i = 1 TO G
PRINT q(i)
NEXT

Tom Lake


Bob May

unread,
Apr 13, 2001, 3:05:39 PM4/13/01
to
That's an interesting question in some respects as the types of the
variables tends to make a difference in the answer. If they are all the
same, dynamic resizing of an array is a nice way to do this. If the
variable types are different, you really end up with problems.
Also involved in this is what you are going to do with the variables as you
need to have the variable defined before you can use it in any calculations,
etc.
For example, if you have an equation that uses G6 but you only have G1-5,
you have a problem that creates a runtime error trying to use G6 as the
value of it is undefined. Thus, you have to define the variables
beforehand.


0 new messages