HELP!!!! - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: HELP!!!! (/thread-122.html) |
HELP!!!! - Orisha - 02-01-2003 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? HELP!!!! - na_th_an - 02-01-2003 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. HELP!!!! - Orisha - 02-01-2003 thanks, i'll go try that right now HELP!!!! - Orisha - 02-01-2003 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 HELP!!!! - na_th_an - 02-01-2003 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) HELP!!!! - Orisha - 02-01-2003 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 HELP!!!! - toonski84 - 02-01-2003 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 #) |