Qbasicnews.com
July 11, 2020, 11:46:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Access to data  (Read 1301 times)
brucem
New Member

Posts: 1


« on: March 31, 2004, 10:37:30 PM »

The last time I programmed was with GW Basic, over ten years ago. With that program, I was able to use a matrix format to store information that I could use repeatedly, modifying it each time a little bit, in one run. If I remember right, I had to dimension the size of the matrix first, and then I could set up a counter that would locate a specific piece of data in the matrix. How is this done in QBasic? I have just started using QBasic and am just beginning to learn the ropes. (The matrix size I used before was 60 x 60)

Thanks for any help!
--Bruce
Logged
Pyrodap
Senior Member
**
Posts: 166



« Reply #1 on: March 31, 2004, 11:24:01 PM »

Code:
DECLARE SUB UpdateMatrix (FileName$)
DECLARE SUB LoadMatrix (FileName$)
DECLARE SUB MakeMatrix (FileName$)
DIM SHARED Matrix$(60, 60)


SUB LoadMatrix (FileName$)
        OPEN FileName$ FOR INPUT AS #1
        FOR y = 1 TO 60
        FOR x = 1 TO 60
        INPUT #1, Matrix$(x, y)
        NEXT
        NEXT
        CLOSE #1
END SUB

SUB UpdateMatrix (FileName$)
        OPEN FileName$ FOR OUTPUT AS #1
        FOR y = 1 TO 60
        FOR x = 1 TO 60
        m$ = m$ + Matrix$(x, y) + ","
        NEXT
        PRINT #1, LEFT$(m$, LEN(m$) - 1)
        m$ = ""
        NEXT
        CLOSE #1
END SUB

SUB MakeMatrix(FileName$)
        OPEN FileName$ FOR OUTPUT AS #1
        FOR y = 1 TO 60
        FOR x = 1 TO 60
        m$ = m$ + "Empty!,"
        NEXT
        PRINT #1, LEFT$(m$, LEN(m$) - 1)
        m$ = ""
        NEXT
        CLOSE #1
END SUB



Okay! that's not too hard.

Before you do anything, you have to have a matrix created. Just call:
Code:
MakeMatrix "Matrix.txt"

Now remember, after a Matrix is created, if you call this sub again it will erase everything in the matrix. Once you have a matrix made, you have to load it.
Code:
LoadMatrix "Matrix.txt"

Once it is loaded, all you have to do to change a value is this:
Code:
Matrix$(10, 10) = "Yay!!"

That will change the value of the 10 by 10 of the matrix to "Yay!!" Now, even though it is changed in the program, it isn't saved. The last thing you do before you close the program is:
Code:
UpdateMatrix "Matrix.txt"

And that's it!

I hope this will suffice, but if not i'll be right here!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!