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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message base with QBasic

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
0
0
US
I am working on an old BBS program (my own) on an old 80's computer that is accessible via Telnet.

I need to write a message base to store messages in a file, maybe titles, to, from, date, msg # in another file.

I want it to be able to delete messages say once a board hit's 30 messages it deletes the old message.

I have not figured out how to do this in Qbasic yet. Does anyone have anything i can use maybe a message base already done that I can modify for my use or can help me get this done?

You will get credit on the BBS for the coding.
 
Yes, using a record structure.

TYPE myRecord
name AS STRING * 20
age AS INTEGER
sex AS STRING * 1
END TYPE

DIM r AS myRecord

;Writing
r.name = "Jeff"
r.age = 30
r.sex = "m"

OPEN "file.txt" FOR RANDOM AS #1
PUT #1, <record_number>, r ;not providing a record number increments the file pointer automatically. Although, one should be provided if able.
CLOSE #1

;Reading
OPEN "file.txt" FOR RANDOM AS #1
GET #1, <record_number>, r ;not providing a record number increments the file pointer automatically. Although, one should be provided if able.
CLOSE #1

PRINT "name: ", r.name
PRINT "age: ", r.age
PRINT "sex: ", r.sex

-Geates

 
Geates,

Would this code delete the oldest message once the messages past #30 in count?
 
AS far as the writing, at the top set current record cr=1

whenever you put a record (put #1,cr)increment the current record cr=cr+1
if cr=31 then make cr=1

this is a rotating storage, once the queue is filled the oldest scrolls off on next put

Nothing mentioned yet of how you want to read the messages, either bulk or singly.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
To calculate number of records (cr - 1), you divide the Length Of File "file.txt" (LOF(<file_number>) = LOF(1)) by the length of myRecord (20 bytes + 2 bytes + 1 byte = 23 bytes).

Code:
'define record type
TYPE myRecord
   name AS STRING * 20  '20 bytes
   age AS INTEGER       ' 2 bytes
   sex AS STRING * 1    ' 1 byte
END TYPE

DIM newPost AS myRecord

'A user just submitted a new post.  Let's write it to file.txt
OPEN "file.txt" FOR RANDOM AS #1 LEN = LEN(myRecord) 'Providing a LEN is necessary for RANDOM access - it gives the computer context of the data.
   numRecords = LOF(1)
   cr = numRecord + 1
   IF (cr > 30) THEN cr = 1
   PUT #1, cr, newPost
CLOSE #1

-Geates

PS. I haven't programmed in qbasic for at least 5 years so there may be mistakes.















 
In the ones I did long ago I didn't worry about variable length, I used the default record length. I did a get as the first part of the write program to insure a full overwrite.

May have Q mixed up with GW but recall LSET as the transfer method.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top