Thread View: alt.lang.basic
3 messages
3 total messages
Started by Paul Young
Fri, 13 Apr 2001 07:34
Simple basic query (I think)
Author: Paul Young
Date: Fri, 13 Apr 2001 07:34
Date: Fri, 13 Apr 2001 07:34
18 lines
1859 bytes
1859 bytes
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
Re: Simple basic query (I think)
Author: Tom Lake
Date: Fri, 13 Apr 2001 13:21
Date: Fri, 13 Apr 2001 13:21
33 lines
2223 bytes
2223 bytes
> 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
Re: Simple basic query (I think)
Author: Bob May
Date: Fri, 13 Apr 2001 19:05
Date: Fri, 13 Apr 2001 19:05
11 lines
2053 bytes
2053 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads