Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Will anyone help me with my project?
#31
Well guys thanks, i got the delete record working now.

SUB delvid
DIM vid AS videotype
CLS
DO UNTIL response$ = "n"
INPUT "Please enter video's bar code number", number
vid.id = number

OPEN "vid.id" FOR RANDOM AS #1 LEN = LEN(vid)
GET #1, vid.id, vid
CLOSE #1

PRINT "This is the video's name", vid.vidname
PRINT "This is the video's main actor", vid.vidactor
PRINT "This is the video's rating", vid.vidratin
PRINT "This is the video's genre", vid.vidgenre
INPUT "Do you wish to delete the above data?", responset$
IF responset$ = "y" THEN
KILL "vid.id"
PRINT "You deleted the data"

ELSE
PRINT "You cancelled the delete"
END IF

INPUT "Do you wish to delete another record?", response$
LOOP
CLOSE #1

END SUB

EVERYTHING RUNS!!!

Okay i got 2 more subs left.
They are list and edit. Could you give me some advice.
ill Gates time is almost up.... i am taking over
Reply
#32
Whoah, whoah, whoah. Hold up. Your program is not doing what you think it is. You have to redo your deletevid SUB.

"KILL" statement deletes a file from your hard disk. An entire file. Not one record in a file. You will not use KILL for this project.

To delete a video from your file, you need to do this:

1. ask the user what video ID they want to delete.
2. set all the fields in your record variable to blank.
3. PUT the record variable into the file in slot ID.

It's doing the same thing as the ADDVID subroutine, except that instead of the record variable containing data, it is empty.

==============================================

I'm going to give you some pretty big help here because I can see that you're having a bit of trouble understanding how record variables and random files work:

Code:
I. Initialization
   A. TYPE VideoType
   B. DIM SHARED vid AS VideoType
II. Main Menu
   A. Add Video
      i. INPUT vid elements
      ii. OPEN file
      iii. PUT vid into file at spot vid.id
      iv. CLOSE file
   B. Delete Video
      i. INPUT vid.id to delete
      i. set vid elements to blanks (except vid.id)
      ii. OPEN file
      iii. PUT vid into file at spot vid.id
      iv. CLOSE file
   C. List Videos
      i. OPEN file
      ii. DO UNTIL EOF(1) <--- until the end of the file is encountered
      iii. increase a "counter" variable by 1
      iv. GET vid from file at spot "counter"
      v. display vid elements to screen if they aren't blank.
      vi. LOOP
      vii. CLOSE file
   D. Search Video
      i. INPUT vid.id to search for
      ii. OPEN file
      iii. GET vid from file at spot vid.id
      iv. display vid elements to screen
      v. CLOSE file

=========================================

Okay, there you go. I think those are the basic steps you need to follow to make your program work. Notes:

All OPEN file commands will be identical:
Code:
OPEN "filename goes here" FOR RANDOM AS #1 LEN=LEN(vid)

The *only* DIM statement will be in the main program, underneath the TYPE block. You will not need to DIM anything in a SUB.
Code:
DIM SHARED vid AS VideoType
(or as whatever you named the TYPE block)

Please ask questions if you don't follow any part of this.

*peace*

Meg.
Reply
#33
I was with you up until.........to delete a video from your file, you need to do this.

Okay well i checked out the program i added two files and deleted one and the entire thing was wiped out.

So okay, let me see if i understand.

SUBDELVID

DIM vid AS videotype
CLS
DO UNTIL response$ = "n"
Input "Please enter video's barcode number", number
vid.id= number.

Okay so what do i gotta do from here. Would you mind to explain step by step from here till the end of this sub. I am kind of confused. How am i supposed to set the vid elements to blanks??
ill Gates time is almost up.... i am taking over
Reply
#34
Sad Heh heh, I thought you wanted the whole file gone, sorry, :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#35
Alright, I'll go over the whole thing from the top:

================================================
STEP 1: Understanding TYPE, DIM, and what is a record variable

================================================

you have this TYPE block, right?

Code:
TYPE VideoType
  id AS INTEGER
  title AS STRING * 50 (or however long)
  actor AS STRING * 50 (or whatever)
  rating AS STRING * 50 (or whatever)
END TYPE

think of your TYPE as like a template. each element becomes a part of whatever variable you DIM as this TYPE:

Code:
DIM VideoIRentedLastWeek AS VideoType

This line of code makes a variable called VideoIRentedLastWeek. Because it is defined as being of type "VideoType", it will inherit the elements of the template: id, title, actor, and rating. VideoIRentedLastWeek is known as the record variable.

Now, you can manipulate the record variable ELEMENTS just like you could any regular variable. For example, VideoIRentedLastWeek.id is defined as an INTEGER (in the TYPE block). Therefore, I can perform actions on it just like a regular integer:

Code:
VideoIRentedLastWeek.id = 5
VideoIRentedLastWeek.id = VideoIRentedLastWeek.id + 1
PRINT VideoIRentedLastWeek

This will output 6.

So, once again, to make a record variable, you do two things:

1. make a TYPE block template.
2. DIM a variable as this TYPE.

Now, you can do this in your main program, outside of your SUBs. But the variable that you DIM will not be accessable within your SUBs unless you create your record variable with DIM SHARED instead of DIM:

Code:
TYPE VideoType
  id AS INTEGER
  actor AS STRING * 50
  rating AS STRING * 50
  title AS STRING * 50
END TYPE
DIM SHARED Vid AS VideoType

There. Now I've made a record variable called "Vid" that I can use in all my SUBs. I will not need any other DIM statements in my program.

================================================
STEP 2: Understanding RANDOM files.
================================================

A RANDOM file is a file that you can read to and write from that is broken up into slots. Each slot will fit exactly one video. Each slot has a number associated with it. The numbers will go from 1 to basically infinity (there is a cap to this, but we won't worry about that, now).

To open your file, the command is:

Code:
OPEN "vidfile.dat" FOR RANDOM AS #1 LEN = LEN(Vid)

This says to open up the file for read & write access and specifies that each slot fits exactly one video. The #1 is just the "file handle" which you use to reference which file you are referring to in your GET and PUT commands. Since we're only working with one file for this project, you will only be using #1.

Think of your RANDOM file as your video store. Each video has a shelf location, labelled by the video id, right? So if you have The Matrix on the shelf, and the shelf is labelled "23", then 23 is The Matrix's id number, and the information on this video should be in slot 23 in your RANDOM file.

You perform two commands on your RANDOM files, GET and PUT. GET retrieves information from the file from a specified slot, and saves it into a record variable:

Code:
GET #1, 23, Vid

This command says GET from file #1 (the only file we have open) the information stored in slot #23, and save this information into our record variable (Vid).

Code:
PUT #1, 23, Vid

This command does the opposite. It says: Take the information in our record variable (Vid) and stuff it into slot #23 in the open file.

================================================
STEP 3: Your SUBs
================================================
Each of your subs performs one action: add a video to your file, remove a video from your file, search your file for a video, Edit a video in your file, or list all the videos in your file. Let's look at each of these actions, one by one.

AddVideo: To add a video, we will need to get the video information from the user, store it into the record variable, OPEN the file, PUT the record variable into the file in the right slot (i.e. on the right shelf), then CLOSE the file.

DeleteVideo: To delete a video, we will need to set the record variable (Vid) to blank values, OPEN the file, PUT the (blank) record variable into the file in the right slot, then CLOSE the file. See, we PUT a blank record variable into the file because this will overwrite any data that might have been in the file in that slot.

SearchVideo: To search for a video, we need to know what video we are looking for. If the user provides the video id, it is easy to find, because you know which slot in the file will have the information they are looking for. So, you get the id from the user, then you OPEN the file, GET the record variable from that slot, display it on the screen, then CLOSE the file.

EditVideo: Again, you need to know which video you're editing. So ask the user for the id. the OPEN the file and GET the record variable from that slot. Then display the information to the user, and see what they want to change. Any changes they make update the record variable. For example, if they want to edit the rating of the video, have them INPUT a new Vid.rating. Then, once they've finished their changes, you PUT the update record variable back into the same slot, then CLOSE the file.

ListVideos: This one is kind of tricky. You need some kind of loop that will go through the file, slot by slot, and see whether a video exists in each slot. If it does, you print it to the screen. The logic goes something like this:

OPEN the file
set a "counter" variable to 1 to indicate that we want to start at the first slot in the file.
start a loop
GET a record from the file (from slot "counter")
check to see whether the record has a title
if it does, print it to screen
advance to the next record (increase the "counter" variable by 1)
end the loop when the End Of File #1 is reached( When EOF(1) is true )

================================================

Okay, I feel like this is the most help that I can give you short of writing the actual program for you, which I would feel wrong doing since this is a school assignment.

However, if you post your code, I will go through it and make suggestions.

Good luck, and I hope this tutorial helps you make a successful program!

*peace*

Meg.
Reply
#36
I wouldn't mind if you did it for me lol. You will feel good knowing because of you i have a PHD in computer when i get older.

Anyhow thanks. I will check your help and try to do my program.
But i still cant seem to understand how to set a blank record. I ahve tried several things but i can't get it

PS i have been meaning to ask you: What is wrong with having dim variable as variable type in all my subs?
ill Gates time is almost up.... i am taking over
Reply
#37
I feel that for this project, having one shared variable DIMmed in one line and shared across all SUBs is just a lot easier to understand. Then you don't need to worry about variable scope.

I don't know how I can explain the delete concept any clearer. If you have data in the file, and you want to "delete" it, you take a blank record and stick it into that slot. That blank record overwrites whatever was in the file in that slot. Therefore, it is deleted.

If you have this:

[AAA][BBB][CCC][DDD][EEE][FFF]

And you send a blank to the fourth slot, then you end up with this

[AAA][BBB][CCC][___][EEE][FFF]

except instead of three-letter strings, it's video records in your file.
Reply
#38
I'm sorry but I have to post this (your sig told me too).

Bill Gates first started out programming in BASIC to small-time businesses for finaces and stuff.... Well work your way up and try it yourself.
i]"But...it was so beautifully done"[/i]
Reply
#39
Okay whatever. When you can explain to me what your post has to do with helping me with my project post back here.

Anyhow Meg i kind of understand now.

What you saying is that i need a blank file to overite the existing file i wish to delete.

Could you like tell me how i gotta go about doing this. Do i have to go in notepad and create a new file like how i created vid.bas?

Is this secondary plan gonna work?:

How about i store the file i wish to delete into a new file such as vide.bas??
But because of the way i have structured the program, if the examiner deletes it and tries to search it, because in the search i have used vid instead, he wont see it.

Is the plan good?
ill Gates time is almost up.... i am taking over
Reply
#40
Hmm.. ok, I haven't reached you with the way this whole RANDOM file thing works yet. You are not creating a blank *file*. You are writing a blank *record* to the file. For clarification:

record template: the information inside of your TYPE statements. This template tells your program what elements are part of any record variable DIMed as this type. In your program, videotype is the record template.

record element: any variable that is defined in the TYPE block which gets inherited by the record variable when it is DIMmed. In your program, the record elements are: .id, .vidname, .vidgenre, .vidactor, and .vidrating

record variable: the variable that contains the elements defined in the TYPE block. In your program, Vid is the record variable. So when I say "record variable" I am talking about Vid, which is composed of Vid.id, vid.vidgenre, vid.vidactor, and vid.vidrating.

random FILE: just like any other file, this is just a thing that sits on your hard drive. When you OPEN the file as RANDOM, it lets you read and write RECORDS to and from the file. Whole record variables, or "vid" in this program. Your file can store lots and lots of record variables into "slots".

Think of your file as a row of numbered boxes. Each box can either hold ONE record variable, or NO record variable. The boxes are numbered in order, from 1, up. To copy your record variable to the file, you PUT:

Code:
PUT #1, boxnumber, Vid

This will take whatever values are held in Vid, and copy them to the box in the file.

To retrieve the contents of one of the boxes in the file, you GET:

Code:
GET #1, boxnumber, Vid

This will take whatever values are in the box in the file, and copy them to Vid.

Soooooo, what does this mean? If you want to DELETE a video from your file, you need to EMPTY the box. How do you empty a box in the file? By putting a BLANK record variable there. How do you make a blank record variable? By setting its elements to blank strings:

Code:
Vid.vidname = ""
Vid.vidgenre = ""
Vid.vidactor = ""
Vid.vidrating = ""
PUT #1, boxnumber, Vid

Does this make any sense at all?

*peace*

Meg.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)