Qbasicnews.com
April 01, 2020, 06:07:38 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: HELP!!!!  (Read 3944 times)
Orisha
New Member

Posts: 6


WWW
« on: January 31, 2003, 04:52:14 PM »

I don't know crap about QBASIC, except for a few things i've been able to read here and there. I need to read in a text file line by line, each line as an array. then I need to change elements 6 trhough 9 and create a new output file. any idea? Wink
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: January 31, 2003, 05:18:30 PM »

Yeah. Use DIM to make your array, OPEN the file FOR INPUT AS #1, do a loop WHILE NOT EOF(1), read the file with INPUT #1, array, WEND, then CLOSE the file.

Try to do it. If you get stuck then we'll help you.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Orisha
New Member

Posts: 6


WWW
« Reply #2 on: January 31, 2003, 05:20:26 PM »

thanks, i'll go try that right now
Logged
Orisha
New Member

Posts: 6


WWW
« Reply #3 on: January 31, 2003, 05:48:33 PM »

ok, this is what i got so far, and it's not working:

CLS
DIM INFO$(500)
OPEN "T:\SAMPNET\SAMPLE.DAT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, INFO$
A = INT(RND * 9)
B = INT(RND * 9)
C = INT(RND * 9)
D = INT(RND * 9)
INFO(1) = A
INFO(2) = B
INFO(3) = C
INFO(4) = D
WEND
CLOSE
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #4 on: January 31, 2003, 06:42:16 PM »

I think I know what you are trying. You are trying to read a file to memory, then change some elements, the write the file again... I guess the elements are numbers, and that the 500 cells array is big enough. If this doesn't work, then tell me which kind of file you are trying to open.

Code:
DIM Info%(500)
OPEN "thefile.fil" FOR INPUT AS #1
index%=0
WHILE NOT EOF(1)        ' While not end of file 1
   INPUT #1, Info%(index%)   ' Read from file.
   index% = index% + 1         ' next time, next array cell.
WEND
CLOSE #1
' Now the data in the file is in memory. Let's change values
' 6, 7, 8 and 9. I dunno what you want to do with your data,
' so I'll just put random values
FOR i%=6 TO 9
   Info%(i%) = INT(RND*10)+1
NEXT i%
' Now write the file:
OPEN "thefile.out" FOR OUTPUT AS #1
' Note that index% is the number of records plus 1, so...
FOR i%=0 TO index%-1
   PRINT #1, Info(i%)
NEXT i%
CLOSE #1
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Orisha
New Member

Posts: 6


WWW
« Reply #5 on: January 31, 2003, 06:53:41 PM »

CLS
DIM INFO$(500)
OPEN "T:\SAMPNET\SAMPLE.DAT" FOR INPUT AS #1
OPEN "T:\SAMPNET\SAMPLE.OUT" FOR OUTPUT AS #2
WHILE EOF(1)
INPUT #1, INFO$
PRINT #2, INFO$
WEND
CLOSE


WELL ACTUALLY I TRIED THIS CODE I JUST POSTED AND IT CREATES A NEW FILE WITH THE SAME DATA. SO I THOUGHT I WAS GOING ALONG THE RIGHT TRACK. THE PROBLEM IS THAT THE FIELDS I WANT TO CHANGE ARE THE LAST FOUR DIGITS OF A NUMBER, BUT MY ARRAY HAS LETTERS AND NUMBERS, SO I DECLARED IT WITH $. IF I TRY TO RANDOMLY GENERATE THE INTEGERS FOR THE LAST FOUR DIGITS IT WON'T WORK, BECAUSE I'LL HAVE THE VALUES STORED IN AN INT VARIABLE AND MY ARRAY IS $, I'M SURE THERE'S GOT TO BE A WAY TO CONVERT THE VARIABLE, BUT I HAVE NO CLUE WHAT IT IS. HERE IS HOPING YOU DO Wink
Logged
toonski84
__/--\__
*****
Posts: 2567



« Reply #6 on: January 31, 2003, 07:11:42 PM »

well, here's the way files work:  you either have input (reading), output (writing) or append (adding to).  if you want to merely *change* something, you have two options:

read the entire file, change what's needed, rewrite the entire file

or

somehow figure out the exact position in bytes of that part, and change it with binary access. (get # and put #)
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
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!