Random Access File Hint for me....

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Mike Alexander
Coder
Posts: 19
Joined: Fri Dec 01, 2006 8:27 pm
Location: Temecula, Ca
Contact:

Random Access File Hint for me....

Post by Mike Alexander »

Hello again...

Here is what I am trying to do...

I run a BBS ... You know, one of them old timey things from 1990's...

Anyway, I have DoorGames... I want to track usage for these doors... Here is my vision...

I would like to create a program that will track the usage of each door. I have a method by which I can call my program (I will call it DOORGRAF for our discussion) and send the name of the game as a parameter... Thanks to the earlier help... COMMAND$ is great... so anyway....

The call to my program would be like DOORGRAF.EXE MYGAME

When it is called, I want it to search my Random access file to determine if the game exists in the records... If not, then create a new record... If it does exist then add one to the number of times the game has been accessed as well as record the date of the file access...

As for the Graphs I think I can do what needs to be done to create graphs... At least I have an idea on what I want it to look like...



ANOTHER THOUGHT/QUESTION

For the Graphs section, I want it to be in order from Largest # of times played to Least Number of Times played... How can I search through XX Number of records and arrage it (not changing the actual data file) order for my graph... Seems like a tedious process to go though for a large number of records to arrange them in that type of order.... Err any type of order for that matter...


-----------------Start of Code Here --------------------

WHATGAME$ = ltrim$(rtrim$(command$)) 'find location of space delimiter between filenames.
NUMOFRECORDS =5 'Number of records in file 1 to 32000
DEBUG = 1 'Set to 1 for debugging

TYPE GAMERECORD
GAMENAME AS STRING * 30 'Name of Game
GAMEPLAYS AS INTEGER 'How Many Times is has been played
GAMELASTPLAY AS STRING * 10 'When was it last accessed
END TYPE

DIM GAME as GAMERECORD

If WHATGAME$ = "MAINT" Then
'ENTER THE DATABASE MAINT MODE

ELSEIF WHATGAME$ = "MAKEGRAF" Then
'Make the Graphs

ELSEIF WHATGAME$ = "RESET" Then
GAME.GAMENAME = "EMPTY"
GAME.GAMEPLAYS = 0
GAME.GAMELASTPLAY = "NEVER"
OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME)
FOR RECORD = 1 to NUMOFRECORDS
PUT #1, RECORD, GAME
NEXT RECORD
CLOSE #1

ELSEIF WHATGAME$ = "SHOWRECORDS" THEN
OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME)
FOR RECORD = 1 to NUMOFRECORDS
GET #1, RECORD, GAME
IF DEBUG = 1 THEN 'DEBUG ONLY
PRINT GAME.GAMENAME
PRINT STR$(GAME.GAMEPLAYS)
PRINT GAME.GAMELASTPLAY
SLEEP 1
END IF
NEXT RECORD
ELSE
'SEARCH FOR THE RECORD IN THE FILE
CURRENTGAME$ = WHATGAME$
OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME)
For Record = 1 to NUMOFRECORDS
Get #1, RECORD, GAME
IF LTRIM$(RTRIM$(GAME.GAMENAME)) = CURRENTGAME$ THEN 'RECORD FOUND
GAME.GAMEPLAYS = GAME.GAMEPLAYS + 1
GAME.GAMELASTPLAY = DATE$
PUT #1, RECORD, GAME
RECORD = NUMOFRECORDS
ELSEIF GAME.GAMENAME = "EMPTY" THEN 'EMPTY RECORD FOUND
GAME.GAMENAME = CURRENTGAME$
GAME.GAMEPLAYS = 1
GAME.GAMELASTPLAY = DATE$
PUT #1, RECORD, GAME
RECORD = NUMOFRECORDS
END IF
NEXT RECORD
CLOSE #1
END IF
Last edited by Mike Alexander on Sun Dec 03, 2006 6:37 pm, edited 3 times in total.
http://ultimate.4alexanders.com
telnet://ubbs2006.synchro.net
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

they have door programs for this i beilieve, at least when i use
to run a wildcat BBS, they did....

you could use BATCH stuff but its easier to use a door program
i think one is called "doorstat" if i am not mistaken...

which BBS system are you using?


go here they can help i'm sure....

http://www.bbsmates.com/
Mike Alexander
Coder
Posts: 19
Joined: Fri Dec 01, 2006 8:27 pm
Location: Temecula, Ca
Contact:

Post by Mike Alexander »

I run Synchronet.
http://ultimate.4alexanders.com

I realize there are doors for this, but you know, none of those ever do what you want them to do.

A lot of the fun is making the program like you want, but never having messed with Random Access files makes the task difficult. I could use a standard text file, but I want to learn the Random Access stuff... I read a couple of the QBasic books and looked at the examples, but I can not figure out how to relate this to what I want to do...
http://ultimate.4alexanders.com
telnet://ubbs2006.synchro.net
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

ANOTHER THOUGHT/QUESTION

For the Graphs section, I want it to be in order from Largest # of times played to Least Number of Times played... How can I search through XX Number of records and arrage it (not changing the actual data file) order for my graph... Seems like a tedious process to go though for a large number of records to arrange them in that type of order.... Err any type of order for that matter...
If the data that you want to sort (arrange) is strictly ASCII text, and you have it on a text file, you can use a DOS utilility called SORT. Do SORT /? from the DOS commandline.

Example:
Assuming this text file was called xxx.txt, the key to sort on was at the front of each record, and the sorted output goes to the same file, you could do the following from your program:
SHELL "cmd/c SORT xxx.txt /o xxx.txt"

See other options/parameters for SORT as required.

You can buy other sort utilities with many more options, such as Opt-Tech Sort, but it costs about $150.

Regards..... Moneo
Mike Alexander
Coder
Posts: 19
Joined: Fri Dec 01, 2006 8:27 pm
Location: Temecula, Ca
Contact:

Post by Mike Alexander »

moneo wrote:
Example:
Assuming this text file was called xxx.txt, the key to sort on was at the front of each record, and the sorted output goes to the same file, you could do the following from your program:
SHELL "cmd/c SORT xxx.txt /o xxx.txt"

See other options/parameters for SORT as required.

You can buy other sort utilities with many more options, such as Opt-Tech Sort, but it costs about $150.

Regards..... Moneo
Or I could do this.... What do you think of my progress so far?

--------------------- Latest Code Here ------------------
WHATGAME$ = ltrim$(rtrim$(command$)) 'find location of space delimiter between filenames.
NUMOFRECORDS =5 'Number of records in file 1 to 32000
DEBUG = 1 'Set to 1 for debugging

TYPE GAMERECORD
GAMENAME AS STRING * 20 'Name of Game
GAMEPLAYS AS INTEGER 'How Many Times is has been played
GAMELASTPLAY AS STRING * 10 'When was it last accessed
END TYPE

DIM GAME as GAMERECORD

If WHATGAME$="" THEN 'OOPS Forgot the parameter or GAMENAME
CLS
BEEP
PRINT "Need to enter a GAMENAME or PARAMETER after DOORSTAT.EXE"
PRINT ""
PRINT "For Example:"
PRINT "---------------------------------------------------------------------"
PRINT "DOORSTAT.EXE BRE ----------> Add BRE to database or increment counter
PRINT "DOORSTAT.EXE MAINT --------> Enter Database Maint mode"
PRINT "DOORSTAT.EXE MAKEGRAF -----> Generate the Usage Graphs"
PRINT "DOORSTAT.EXE RESET --------> RESET THE USAGE FILE"
PRINT "DOORSTAT.EXE SHOWRECORDS --> Display all records to screen"
SLEEP 1
BEEP
SYSTEM
END IF

If WHATGAME$ = "MAINT" Then
'ENTER THE DATABASE MAINT MODE

ELSEIF WHATGAME$ = "MAKEGRAF" Then 'Make the Graphs
OPTION BASE 1
DIM NAMEOFGAME$(NUMOFRECORDS), NUMOFGAMEPLAYS%(NUMOFRECORDS), LASTPLAYDATE$(NUMOFRECORDS), BARSONGRAPH%(NUMOFRECORDS)

OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME) 'Read all records and store into Array
FOR RECORD = 1 to NUMOFRECORDS
GET #1, RECORD, GAME
NAMEOFGAME$(RECORD) = GAME.GAMENAME
NUMOFGAMEPLAYS%(RECORD) = GAME.GAMEPLAYS
LASTPLAYDATE$(RECORD) = GAME.GAMELASTPLAY
NEXT RECORD
CLOSE #1
'Sort in # of Play order Most played to least played
For record = 1 to NUMOFRECORDS
For RECORDPLUSONE = record + 1 to NUMOFRECORDS
IF NUMOFGAMEPLAYS%(RECORD) < NUMOFGAMEPLAYS%(RECORDPLUSONE) THEN
SWAP NUMOFGAMEPLAYS%(RECORD), NUMOFGAMEPLAYS%(RECORDPLUSONE)
SWAP NAMEOFGAME$(RECORD), NAMEOFGAME$(RECORDPLUSONE)
SWAP LASTPLAYDATE$(RECORD), LASTPLAYDATE$(RECORDPLUSONE)
SWAP BARSONGRAPH%(NUMOFRECORDS), BRASONGRAPH%(RECORDPLUSONE)
END IF
NEXT RECORDPLUSONE
NEXT RECORD
' NEED TO DETERMINE THE MAXIMUM RANGE OF THE GRAPH
' THE FIRST RECORD IS THE MAX RANGE and determine the SCALE
' We only have 50 spaces to play with...
GRAPHMAXVALUE = NUMOFGAMEPLAYS%(1) ' can be as high as 32K
GRAPHMINVALUE = 0 ' Min is always 0
GRAPHSCALE = 50/NUMOFGAMEPLAYS%(1) ' Set GRAPH SCALE = 50 spaces / max # games (This is the Multiplier)
' Each game is worth GRAPHSCALE "points"
For RECORD = 1 to NUMOFRECORDS ' Populate the array with the correct # of Character for the Graph
BARSONGRAPH%(RECORD) = INT(GRAPHSCALE * NUMOFGAMEPLAYS%(RECORD))
NEXT RECORD

IF DEBUG = 1 THEN 'Used to see debug stuff
For RECORD = 1 to NUMOFRECORDS
Print "-------------- RECORD # " + STR$(RECORD) +" -------------------"
Print "NAME -------------- " + NAMEOFGAME$(RECORD)
Print "# of Plays -------- " + STR$(NUMOFGAMEPLAYS%(RECORD))
Print "DATE LAST PLAYED -- " + LASTPLAYDATE$(RECORD)
Print "# of Graf CHARS --- " + STR$(BARSONGRAPH%(RECORD))
PRINT "-----------------------------------------------"
PRINT ""
SLEEP 1
Next RECORD
END IF





HEADER1$ ="[?7h[40m[2J[40m"
HEADER2$ ="[0;1;34m???????????????????????????????????????????????????????????????????????????????"
HEADER3$ ="???????????????????????????????????????????????????????????????????????????????"
HEADER4$ ="???????????????????????????????????????????????????????????????????????????????"
HEADER5$ ="???[73C???"
HEADER6$ ="??? [0;34m??????? ??????? ??????? ??????? ??????? ??????? ??????? ??????? ??????? [1m???"
HEADER7$ ="??? [0;34m?? ?? ?? ?? ?? ?? ?? ?? ?????? ??? ??????? ??? ?????? [1m???"
HEADER8$ ="??? [0;34m?? ?? ?? ?? ?? ?? ?????? ?????? ??? ??????? ??? ?????? [1m???"
HEADER9$ ="??? [0;34m??????? ??????? ??????? ?? ??? ??????? ??? ?? ?? ??? ??????? [1m???"
HEADER10$ ="???[73C???"
HEADER11$ ="???????????????????????????????????????????????????????????????????????????????"
HEADER12$ ="???????????????????????????????????????????????????????????????????????????????"
HEADER13$ ="???????????????????????????????????????????????????????????????????????????????"
HEADER14$ = "" 'PUT THE AUTO ADJUSTING TICKER BAR HERE

'if DEBUG = 1 THEN
' PRINT HEADER1$:PRINT HEADER2$:PRINT HEADER3$:PRINT HEADER4$:PRINT HEADER5$:PRINT HEADER6$
' PRINT HEADER7$:PRINT HEADER8$:PRINT HEADER9$:PRINT HEADER10$:PRINT HEADER11$:PRINT HEADER12$
' PRINT HEADER13$:PRINT HEADER14$
'END IF





PRINT CHR$(220) + CHR$(220) + CHR$(220)



ELSEIF WHATGAME$ = "RESET" Then
GAME.GAMENAME = "EMPTY"
GAME.GAMEPLAYS = 0
GAME.GAMELASTPLAY = "NEVER"
OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME)
FOR RECORD = 1 to NUMOFRECORDS
PUT #1, RECORD, GAME
NEXT RECORD
CLOSE #1

ELSEIF WHATGAME$ = "SHOWRECORDS" THEN
OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME)
FOR RECORD = 1 to NUMOFRECORDS
GET #1, RECORD, GAME
PRINT GAME.GAMENAME
PRINT STR$(GAME.GAMEPLAYS)
PRINT GAME.GAMELASTPLAY
IF DEBUG = 1 THEN 'DEBUG ONLY
SLEEP 1
END IF
NEXT RECORD
ELSE
'SEARCH FOR THE RECORD IN THE FILE
CURRENTGAME$ = WHATGAME$
OPEN "DOORSTAT.DAT" AS #1 LEN = LEN(GAME)
For Record = 1 to NUMOFRECORDS
Get #1, RECORD, GAME
IF LTRIM$(RTRIM$(GAME.GAMENAME)) = CURRENTGAME$ THEN 'RECORD FOUND
GAME.GAMEPLAYS = GAME.GAMEPLAYS + 1 'Add one to existing Record
GAME.GAMELASTPLAY = DATE$ 'Use Todays date for Last Play
PUT #1, RECORD, GAME 'Write Record
RECORD = NUMOFRECORDS 'Jump to End
ELSEIF LTRIM$(RTRIM$(GAME.GAMENAME)) = "EMPTY" THEN 'Not an Existing Game in database
GAME.GAMENAME = CURRENTGAME$ 'Add this game as new record
GAME.GAMEPLAYS = 1 'Set to first play
GAME.GAMELASTPLAY = DATE$ 'Set Todays Date
PUT #1, RECORD, GAME 'Write Record to File
RECORD = NUMOFRECORDS 'Jump to End
END IF
NEXT RECORD
CLOSE #1
END IF
http://ultimate.4alexanders.com
telnet://ubbs2006.synchro.net
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Sorry, Mike, but I won't be able to help you with this.
1) I never use Random files, so I don't understand them.
2) I never use Type Declarations, ditto.
3) My regular PC is broke and I'm using my daughter's laptop which has no QB stuff.

Your sort looks like a modified bubble sort. If it works, then that's ok. Be careful that you make sure that you always have at least 2 elements to sort, otherwise it might bomb.

Good luck, and regards..... Moneo
Post Reply