Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Will anyone help me with my project?
#1
Hey guys i am new here.

We just started studying QBASIC in school and i got like 2 weeks before i gotta hand up my school based assesment.

Now i am a little new to Basic, so i seem to encounter lots of problems doing this project. And asking the teacher for help is not an option because the rule states he is gonna have to deduct 20 marks off the SBA. I have know knowledge on the features of basics, i have read up on it however and i got a good idea of it.

Well, the project deals with developing a database for a company.
So i chose a video store.
So the modules are:

1. Add a video
2. Delete a video
3. List all videos
4. Edit
5. Search
6. Exit
7. Main menu

Now i got the add video and main menu running. But now i am trying to work on the search vid. I got loads of errors occuring help please.
ill Gates time is almost up.... i am taking over
Reply
#2
Post your code. ^-^
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Are you sure that we want to help with this guys homework?

Heh...I wish I was back in my QB class, I never cheated.

But if you post your code I think that we can help with any errors you have, and tell you to go look up some things in your HELP file.
i]"But...it was so beautifully done"[/i]
Reply
#4
Smile Yeah, we do loads more help when we see your coding style and how you got it put togetter.. then we can find errors and send them back to you.. so post a source if you want good help..

Homework, at least its not like the one where they wanted the whole code strait up,. :wink: ,. say, as for the HELP file can help alot.. where you have a error, move the Typing cruser to the Statment, hit HELP, on the menu hit Topic:,. it takes you right to the details on the sentax and give you examples to use.. Smile
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#5
[/code]

How do i post the code on this forum?
ill Gates time is almost up.... i am taking over
Reply
#6
1) Open the code in Notepad
2) Copy it
3) Paste it between code brackets
Code:
[code](code goes here)[/code]
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#7
Okay well i have copied and pasted then.



VIDYO.BAS

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


ADDVID

SUB ADDVID

DIM vids AS videotype
OPEN “vid.dat” FOR RANDOM AS # 1
DO UNTIL response$ = “n”
INPUT “please enter video’s bar code number”, number
Vids.id = number
INPUT “enter name of video”,vids.vidname
INPUT “enter name of main actor”,vids.vidactor
INPUT “enter rating of video ?/10”, vids.vidratin
PRINT “YOU ADDED A NEW VIDEO”
INPUT “Do you want to add any more videos”, response$
LOOP
CLOSE # 1
END SUB






SUB searchvid
DIM vids AS videotype
CLS
DO UNTIL response$ = “n”
Input “please enter video’s bar code number”, id
GET # 1, id, vid
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 video?” response$
LOOP
CLOSE#1
END SUB



Okay could you guys see whats the problem with my searchvid and help me please.
ill Gates time is almost up.... i am taking over
Reply
#8
Quick run down on using TYPE blocks used with RANDOM file access:

[syntax="QBASIC"]
'declare your record fields
TYPE RecordType
element1 AS STRING * 50
element2 AS INTEGER
element3 AS STRING * 10
END TYPE

'create a variable to hold one record which will be shared across SUBS
DIM SHARED MyRecord AS RecordType

'fill the record variable with some data
MyRecord.element1 = "This is a 50 character long text string!"
MyRecord.element2 = 354
MyRecord.element3 = "How's it?"

'open file read/write access with record slots equal to record length
OPEN "database.dat" FOR RANDOM AS #1 LEN = LEN(MyRecord)

'fill the first record slot in the file with your record variable
PUT #1, 1, MyRecord

'fill the second record slot in the file with your record variable
PUT #1, 2, MyRecord

'fill your record variable from the 10th record slot in the file
GET #1, 10, MyRecord

'close the file
CLOSE #1
[/syntax]

Hopefully looking this stuff over will give you a good idea of how to use RANDOM along with TYPE declarations.

*peace*

Meg.
Reply
#9
Thanks meg.

But could you guys look into my problem with the search vid and tell me what to do? I tried a zillion things today and still no progress. Why does the teacher want his project in a program he havent even taught us?

Could you guys also give me a way of how to access the database for the edit and search?
ill Gates time is almost up.... i am taking over
Reply
#10
You are running into a problem with variable SCOPE. You are using two record variables in this program: "vid" and "vids", both of TYPE videotype.

vid is DIMmed locally in the main program. It cannot be seen from SUBs.
vids is DIMmed locally in each of the subroutines. It can only be seen in the SUB it is DIMmed in. Its value is gone when the SUB finishes.

When a SUB is called, and there is a variable DIMmed inside of it, the variable can only be accessed from within that SUB. Once the SUB ends, the variable is lost.

If you DIM a variable outside of a SUB, you will not be able to use it inside the SUB unless you do one of two things:

1. declare the variable to be SHARED across subs (see my above post for example). This is the easier method.
2. pass the variable to the SUB, for example:

[syntax="QBASIC"]
'create an integer variable and set its value to 25
MyAge% = 25
'call SUB "ShowMyAge", passing this variable to it
ShowMyAge MyAge%
'end the program
SYSTEM

SUB ShowMyAge (MyAge%)
PRINT "My age is"; MyAge%
END SUB[/syntax]

As far as accessing the database, I showed you how to do that in my previous post. When you open the database for RANDOM, you need to say how long each record is, so it knows how to "divide up" the file into slots. Since each slot fits one video, the length needs to be equal to the length of a variable of type videotype:

[syntax="QBASIC"]
OPEN "nameoffile" FOR RANDOM AS #1 LEN=LEN(vid)
[/syntax]

Finally, nowhere in your ADDVID sub are you actually adding the record variable into your file. You need a PUT statement in there (see my previous post for an example of how PUT works).

*peace*

Meg.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)