Qbasicnews.com

Full Version: Read...Data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, i had to do this project for school and thought u mite be able to help me out...

ok, so i make a menu of all options from 1-10.....now i want to assign strings to the chosen number....
i heard theres a way to use Read...Data and get it...i need to know how..

EXAMPLE :
For Finding Month By Inputting Number:
If i typed the number 8, "August" should be printed on the screen!
You could do it with READ and DATA, but an array would be easier... have you covered arrays yet?
yea i have, but i havent got the hang of it yet..! file handling and arrays are two things i cannot understand in basic!
It's easy, think of it this way.
When you DIM an array, like this:
Code:
DIM myArray(1234 TO 4321)
it's like you're making a city block appear out of nowhere with houses numbered from 1234 to 4321.

And this:
Code:
myArray(2000) = 1.5
just puts the number 1.5 inside house #2000.

This
Code:
PRINT myArray(3232)
PRINTs whatever is in house #3232.

For your example, you'd need an array of strings that goes from 1 to 12, like this:
Code:
DIM monthNames$(1 TO 12)
Then you'd have to put all the month names in the right places in the array.
Code:
monthNames$(1) = "January"
And so on...
Then you'd be ready to give the user an answer - just PRINT the right one using the variable you INPUTed.

Give it a try, you can do it.

If you still really want to use DATA instead, I can explain that too.
Quote:If you still really want to use DATA instead, I can explain that too.
can i? eh oh well because I AM! Mwa ha ha!

First define the array
Code:
DIM months$(1 TO 12)

then read the data statemnts directly into the array number. see? if you dont know what FOR... NEXT is it just does the loop 12 times (see '1 TO 12') and i = the number it is on. So first it reads "Jan" into months$(1) (1 becasue it's the first loop) got it?
Code:
FOR i = 1 TO 12
READ months$(i)
NEXT i

This is of course your data
Code:
DATA "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"
Combining both is a bit easier Big Grin
Quote:Combining both is a bit easier Big Grin
True dat. That's probably exactly what he's supposed to do.
That's a really good explanation of how arrays work, Sterling :o
Quote:That's a really good explanation of how arrays work, Sterling :o
Thanks! 8)
ohhk..now i got it!!
Thanks!