Jump to content

qbasic question (file handling)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Zer033

Zer033

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Hi guys, I know C++ and javascript, but recently I've been messing around with qbasic just out of curiosity. I do have a small problem I was trying to solve for a practical reason using qbasic. The problem is I have these text files that are supposed to be in a constant record length format, but occasionally they are not. They will sometimes have some records throughout that are less than the max record length. This difference messes up the field reading by another program which misaligns all the information. What I wanted to do was just add some characters to those shorter records (or all records because the data in the final field is not important) so that it makes all records uniform. I did write a small program that I thought fixed it, but my testing was with a file that had uniform record lengths already so when I ran it and it did fill in the last characters of each record how I wanted I thought it worked. When I realized what I had done and changed the test file to have a different record length on a few records it messed up when it reached that record.

If you aren't understanding then let me show an example:

Say I have a file with these records

1234567890
1234567890
12345
1234567890
1234567890

My record length would be 10 and my record number would be 5. That middle record that only has a record length of 5 is messing the file up so what I want to do is just add some spaces to that record or the way I originally implemented it add spaces to the last 5 characters of every record (since those last 5 characters don't matter).

I was using OPEN #1 AS BINARY FOR LEN = LEN(recordlength), but I think binary was just counting any bytes that were already present so when I changed the file to not have uniform record lengths it mis-counted and messed the file up. I know how to add records and all that with sequential files and random files from scratch, but this problem is a little different as the entire rest of the file can't be affected, only those last 5 characters of each record can.

#2
Zer033

Zer033

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
No one know how to do this with qbasic?