Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Will anyone help me with my project?
#11
Thanks for the help.

I am gonna try to get this done, if it doesn't i will write back here. This project is due by march 14th so will you guys keep checking here to see if i got any more problems?

And meg bout the put statement would i do it like this:

PUT #1, 1, VID??
ill Gates time is almost up.... i am taking over
Reply
#12
Think of it like this. When you use TYPE, you are creating like a template for a variable... consider a person:

[syntax="QBASIC"]TYPE PersonType
FirstName AS STRING * 20
LastName AS STRING * 20
MiddleInit AS STRING * 1
Age AS INTEGER
FavoriteFood AS STRING * 15
END TYPE[/syntax]

Now that you have made your template, you can use it to define variables:

[syntax="QBASIC"]
DIM Bob AS PersonType
[/syntax]

At which point you can play around with Bob's elements, like Bob.Age, or Bob.FirstName.

Bob is now a record. You could make more people, and DIM them all as PersonType and they would all be records. Every record is exactly the same length. This is very important. Because you define STRING length (for example, FirstName is 20 letters long), each record will have a constant size, no matter how long a first name you set Bob.FirstName equal to. It will just fill the rest of the 20-letter limit with null characters (or spaces, I forget which). So LEN(Bob.FirstName) will always show 20.

When you open a file as RANDOM, you want to be able to read and write records to it. Think of your RANDOM file as a series of mailboxes in a row. Each one has exactly enough room to fit one record, and they are labelled in order, from 1 to ... some really huge number.

However, when you OPEN the file, you need to tell it how big each mailbox needs to be. If your mailbox is too small, Bob's record won't fit in it, and it will spill over to the next mailbox and cause problems.

So, when you OPEN the file, you need to specify the record length.

[syntax="QBASIC"]
OPEN "filename.dat" FOR RANDOM AS #1 LEN=LEN(Bob)
[/syntax]

Now the program knows that each mailbox will fit exactly one record the size of Bob (or any other PersonType defined record, since they're all the same size).

So, to read and write to the file, use GET (read) and PUT (write) as follows:

GET #1, mailboxnumber%, record
PUT #1, mailboxnumber%, record

If you want to put Bob's record information into the 200th mailbox, use:

[syntax="QBASIC"]
PUT #1, 200, Bob
[/syntax]

And if you then want to read Bob's information from the 200th mailbox, use:

[syntax="QBASIC"]
GET #1, 200, Bob
[/syntax]

Simple!

I'll be checking here frequently for posts from you, so that I can help out as quickly as possible.

Good luck!

*peace*

Meg.
Reply
#13
Okay thanks for the help. I tried the put and it worked well for the add mem.

But here is one mroe of my questions.

Well, i have already gotten the add member.
What i wanna know is: If i add say data on you, meg, and then i go in search, how do i re-obtaint he data on you?? Understand. Help me find a way to re-obtain the data added.

MY NEW ADDSUB

sub ADDVID
DIM vids AS videotype
OPEN “vid.dat” FOR RANDOM AS #1 LEN = LEN (vids)
DO UNTIL response$ = “n”
INPUT “please input video’s bar code number”, number
vids.id = number
PUT #!, 1, id
INPUT “enter name of video”, vids.vidname
PUT #1, 2, vidname
INPUT “enyer main actor”, vids.vidactor
PUT #1, 3, vidactor
INPUT “enter rating of video”, vids.vidratin
PUT #1, 4, vids.vidratin
Print “you added a new video”
Input “ do you want to add any other videos”, response$
LOOP
CLOSE#1
ENDSUB

Could you also look into my search mem and tell me what i gotta do. I tried the get command but whenever i run it i keep getting an error. [/code]
ill Gates time is almost up.... i am taking over
Reply
#14
Okay, I've taken the code you posted above, and added my comments to it. After the code, I will explain what parts of your code are causing problems.

[syntax="QBASIC"]
SUB AddVid

'create a variable named "vids" using the "videotype" template...good!
DIM vids AS videotype

'open up the file with the correct record length... good!
OPEN “vid.dat” FOR RANDOM AS #1 LEN = LEN (vids)

'start a loop that will exit when the user hits "n"
DO UNTIL response$ = “n”

'these next two lines get the user to input vids.id; you can combine
'them into one line, however: INPUT "please input...", vids.id
INPUT “please input video’s bar code number”, number
vids.id = number

'this line won't work...see below for why.
PUT #!, 1, id

'okay, now this one you did combine into one line...good!
INPUT “enter name of video”, vids.vidname

'this line won't work...see below for why.
PUT #1, 2, vidname

'get the name of the actor...good!
INPUT “enyer main actor”, vids.vidactor

'this line won't work...see below for why.
PUT #1, 3, vidactor

'get the rating of the video...good!
INPUT “enter rating of video”, vids.vidratin

'this line won't work...see below for why.
PUT #1, 4, vids.vidratin

'tell the user that the video has been added. good!
Print “you added a new video”

'and finally, prompt the user for whether to continue...good!
Input “ do you want to add any other videos”, response$
LOOP

'close the file...good!
CLOSE#1

'end the sub...good! NOTE: At this point, the variable vids will
'disappear, because its scope is only within this AddVid subroutine!
END SUB
[/syntax]

Alright, this code is a very good try. The place you are having problems is with your use of the PUT statement.

Remember the mailbox idea from my last post? Well remember...each mailbox hold one ENTIRE RECORD (id, vidname, vidactor, vidrating). The size of vids (including all of its elements) will fit into ONE SINGLE record slot in your file.

This is what you coded:
[syntax="QBASIC"]
PUT #1, 1, id
PUT #1, 2, vidname
PUT #1, 3, vidactor
PUT #1, 4, vidrating
[/syntax]

You are trying to put one ELEMENT into each record slot. If you want the first video to go into the first "mailbox" in your file, all you need to do is:

[syntax="QBASIC"]
PUT #1, 1, vids
[/syntax]

In other words, when reading and writing from the file, you transfer information in entire RECORDS (like vids), not individual record FIELDS (like vids.rating or vids.actor).

*peace*

Meg.
Reply
#15
meg rox



hey btw is that dungeon game still going?? :o i LoVeD that game
Reply
#16
I actually had the game up and running a few months ago, but something wrecked the BBS I was running, and it got all corrupt. I didn't have the enthusiasm with the project to figure out why.

I had a few people ask me how Dungeon was coded, so I figure I might as well release the source code to it if anyone's interested. It's nothing impressive; like I said from the beginning the real work was contained in a library that I didn't write (EZDoor routines).

Anyway, it is at this point kind of a dead project. I got this old computer I was gonna hook up to the router in our apartment just to run a telnet-based BBS off of, but when I realized the thing didn't have a network card that idea fizzled pretty quickly. Running a BBS on your personal computer is a real nuissance.

*peace*

Meg.
Reply
#17
Guys my program keep getting errors. Could someone just look into my matter with the search mem. The get not working. I need help. Please tell me what i should do.
I have tried everything but say i add info on batman, it works. But when i go back tot he database and try to search for batman i keep getting: Bad Record Number

Also, if i take out the get and i enter the infor on batman to be searched i get the following:


This is the video's name 0
This is the video's genre 0
this is the video rating 0

why?



DECLARE SUB editvid ()
DECLARE SUB addvid ()
DECLARE SUB delvid ()
DECLARE SUB listvid ()
DECLARE SUB searchvid ()
DECLARE SUB LEAVE ()
DECLARE SUB mainmenu ()
TYPE videotype
id AS INTEGER
vidname AS STRING * 50
vidgenre AS STRING * 50
vidactor AS STRING * 50
vidratin AS STRING * 50
END TYPE
DIM vid AS videotype




CLS
mainmenu

SUB addvid

DIM vids AS videotype
OPEN "vid.dat" FOR RANDOM AS #1 LEN = LEN(vids)
DO UNTIL response$ = "n"
INPUT "please enter video's barcode number", number
vids.id = number

INPUT "enter name of video", vids.vidname

INPUT "enter main actor of film", vids.vidactor

INPUT "enter rating of video ?/10 ", vids.vidratin

PRINT "you added a new video"
PUT #1, vids.id, vid


INPUT "do you want to add any another videos? y-Yes, n-No ", response$
LOOP
CLOSE #1

END SUB

SUB delvid
DIM vids AS videotype

END SUB

SUB editvid
END SUB

SUB LEAVE
PRINT "Goodbye user!!!!!"
END SUB

SUB listvid
END SUB

SUB mainmenu
COLOR 10
20 PRINT "WELCOME TO VIDEOTRONICS DATABASE"
30 PRINT "Please Select an Option from below"
40 PRINT "1 - To add a new video"
50 PRINT "2 - Delete a video"
60 PRINT "3 - List all videos"
70 PRINT "4 - search a video"
80 PRINT "5 - Edit video details"
90 PRINT "6 - EXIT DATABASE "
100 INPUT C
SELECT CASE C
CASE IS = 1
addvid
CASE IS = 2
delvid
CASE IS = 3
listvid
CASE IS = 4
searchvid
CASE IS = 5
editvid
CASE IS = 6
LEAVE
CASE ELSE
PRINT "You inserted an invalid option"
GOTO 100
260 END SELECT


END SUB

SUB searchvid
DIM vids AS videotype
CLS
DO UNTIL response$ = "n"
INPUT "please enter video's bar code number", id
OPEN "vid" FOR RANDOM AS #1
get #1, vids.id, vids

PRINT "This is the video's name", vidname.vid
PRINT "this is the video's genre", vidgenre.vid
PRINT " this is the video's main actor", vidactor.vid
PRINT "this is the video's rating", vidratin.vid
INPUT " Do you wish to search for another record?", response$
LOOP
CLOSE #1


END SUB

ill Gates time is almost up.... i am taking over
Reply
#18
Alright! You're real close to having it correct, now! Just a few small changes left....

==============================================
Problem #1: You are still defining two DIFFERENT record variables.:

right after your TYPE statement:
Code:
DIM vid AS videotype

and inside your SUB:
Code:
DIM vids AS videotype

Solution #1: Use only ONE record variable, vid. Get rid of vids alrogether. SHARE vid across SUBroutines in the DIM statement after the TYPE block, instead:

[syntax="QBASIC"]DIM SHARED vid AS videotype[/syntax]

Then, the elements of your record will be referred to throughout the entire program--both inside and outside of SUBs--as:

vid.id
vid.vidname
vid.vidgenre
vid.vidactor
vid.vidratin

Just exactly as they are defined in your TYPE block! So make sure you have them typed like that everywhere in your program. Right now, you don't. In your searchvid SUB, you reference "vidname.vid", "vidgenre.vid", etc.! These are backwards. ^_^

Also, since "vid" is going to be your record variable, make sure your OPEN statements (everywhere in the program) have LEN = LEN(vid), *not* LEN=LEN(vids)!

Also, since "vid" is going to be your records variable, find all instances of vids.id, vids.vidname, etc., and change them to vid.id, vid.vidname, etc. No more "vids" anywhere. Just "vid".
==============================================

==============================================
Problem #2: Your filename is inconsistent.

When you open the file in the addvid SUB, you open "vid.dat", but in the searchvid SUB, you open just plain "vid".

Solution #2: Chance "vid" to "vid.dat" in the OPEN statement within the searchvid subroutine.
==============================================

==============================================
Problem #3: in the searchvids SUB, you ask which record you want to read in from the file, and INPUT this value into the variable "id". However, in your GET command, you do not read from record slot "id" in the file.

Solution #3: change your GET statement:

get #1, vids.id, vids --------- get #1, id, vid

Then, in the PRINT lines immediately after it, make sure you are printing vid.vidname, vid.vidgenre, etc. Like I mentioned above, you've got those wrong at the moment.
==============================================

==============================================
Additional notes for "clean" programming:

You don't need to write CASE IS = 4; CASE 4 will work just fine.

You don't need line number in your mainmenu SUB. This code will do the same thing without using GOTO:

Code:
do
  color 10
  print ""
  print "MAIN MENU LINES GO HERE"
  print ""
  input c
  select case c
    case 1: addvid
    case 2: delvid
    case 3: listvid
    case 4: searchvid
    case 5: editvid
    case 6: leave
    case else: print "You entered an invalid value."
  end select
loop until c = 6
==============================================

*peace*

Meg.
Reply
#19
Wow i feel really stupid.

Well thanks for your help Meg. I have done what you said to do but i keep getting an error with the get and put. They keep saying bad record length. Any ideas?
ill Gates time is almost up.... i am taking over
Reply
#20
Please post your updated code. If you are getting "bad record length" it is probably either:

1. You do not have your record variable "vid" DIM SHARED
2. You do not have LEN=LEN(vid) in your OPEN statement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)