Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I AM GETTING JUNK OUTPUT

Status
Not open for further replies.

qbnovice

IS-IT--Management
May 4, 2001
2
US
I am helping someone learn QBASIC -- Used it a long time ago and here is the sample code that I found on the web and made a test program out of it...

CLS
GOSUB BEGIN
GOSUB PROCESS
GOSUB WRAPUP
END

BEGIN:
TYPE people
nm AS STRING * 40 'set the name as a 40-character string
age AS INTEGER 'set the age as an integer
address AS STRING * 60 'set address as a 60-character string
END TYPE


DIM person AS people

OPEN "address.dat" FOR RANDOM AS #1 LEN = LEN(person)

RETURN

PROCESS:
CLS
person.address = ""
INPUT "What record to add"; record
INPUT "Name"; person.nm
INPUT "Age"; person.age
INPUT "Address"; person.address
PUT #1, record, person
RETURN

WRAPUP:
CLOSE #1
LOCATE 16, 10: PRINT "ADDRESS.DAT IS CREATED"
LOCATE 18, 10: PRINT " PROGRAM COMPLETED"
RETURN

The program runs fine and creates tge .DAT file but there is alot of Junk data in it and it is sometimes as big as 300 KB and it is not the same junk everytime.. Looks like I am having some kind of a buffer problem.. Any help is appreciated.. WHY AM I NOT GETTING A TEXT FILE like a CSV file ... I AM CONFUSED... A novice
 
Free space on your drive does is not alway blank. This garbage you are seeing is either a program or data that has either been deleted, or moved to another part of the disk. You will see this in your data file if you happen to skip some record numbers when you are adding new data in. These records that are skipped reserves the space to be used at a later date,but are not written to, so they can be viewed with notepad or your program.
David Paulson


 
qbnovice:

Dpaulson's right. I noticed it too...this bit of code is intended more for updating then it is for adding/appending.

You are requesting that the User physically puts in a record number:
INPUT "What record to add"; record.

So, if you add record # 1 then you add record #3 the "gap" between 1 and 3 contains whatever was left there from a previous program.

If your intension is to ADD a new record to a [red]BLANK dat[/red] file you should remove the 'record' number in the PUT statement so that it will add/append new ones at the next point of insertion.

If you intend to ADD a new record to an [red]EXISTING dat[/red] file you should use the LOF() and SEEK functions to point to the next point of insertion.

Just as a reminder, after you set your SEEK statment if you will be adding a new record immediately, you do not need to re-SEEK the next insertion point.

Hopefully this clarifies Dpaulson's explaination.

Good Luck.
--MiggyD "The world shrinks more and more with every new user online."
 
Thanks a lot to DPaulson and MiggyD .. That was the problem and I appreciate your input .. I had skipped a record number in a file I was trying to read into this file and got the junk.. You are a great bunch of help.. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top