×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Message base with QBasic

Message base with QBasic

Message base with QBasic

(OP)
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.

RE: Message base with QBasic

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

http://ns7.webmasters.com/caspdoc/html/vbscript_la...

RE: Message base with QBasic

(OP)
Geates,

Would this code delete the oldest message once the messages past #30 in count?

RE: Message base with QBasic

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.

RE: Message base with QBasic

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.













http://ns7.webmasters.com/caspdoc/html/vbscript_la...

RE: Message base with QBasic

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close