Posts: 319
Threads: 68
Joined: Mar 2005
haha figured it out just took some expirementing
Code: DECLARE SUB addnumber ()
DECLARE SUB createnewfile ()
DECLARE SUB reader ()
DECLARE SUB createfile ()
ON ERROR GOTO errorhandler
DIM errorcode AS INTEGER
errorcode = 0
TYPE phonetype
FullName AS STRING * 20
Number AS STRING * 12
END TYPE
DIM SHARED phone(1 TO 100) AS phonetype
CLS
OPEN "phone#.txt" FOR INPUT AS #1
IF errorcode = 53 THEN createnewfile
reader
INPUT "Do you want to add more? ", yn$
IF UCASE$(yn$) = "Y" THEN addnumber
errorhandler:
errorcode = ERR
RESUME NEXT
SUB addnumber
DO
INPUT "What is the name of the person you want to add? ", aname$
INPUT "What is their phone number? ", anumber$
OPEN "phone#.txt" FOR APPEND AS #1
WRITE #1, aname$, anumber$
CLOSE #1
INPUT "Do you want to add more? ", yn$
IF UCASE$(yn$) = "N" THEN EXIT SUB
LOOP
END SUB
SUB createnewfile
CLS
INPUT "Type name of person you want to add ", aname$
INPUT "What is their phone number ", anumber$
OPEN "phone#.txt" FOR OUTPUT AS #1
WRITE #1, aname$, anumber$
CLOSE #1
INPUT "Do you want to add more? ", yn$
IF UCASE$(yn$) = "Y" THEN addnumber
END SUB
SUB reader
DO
i = i + 1
INPUT #1, phone(i).FullName, phone(i).Number
LOOP UNTIL EOF(1)
CLOSE #1
FOR a = 1 TO i
PRINT phone(a).FullName, phone(a).Number
NEXT
END SUB
thanks
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Posts: 319
Threads: 68
Joined: Mar 2005
ok so i read up on the command RANDOM and saving to .dat files and i made it muuuuuch simpler. alright so my question is if you wanted to remove the number from the file how would you do that. like deleting the phone number?
here's the code
Code: DECLARE SUB reader ()
DECLARE SUB addfile ()
TYPE phonetype
FullName AS STRING * 20
Number AS STRING * 12
END TYPE
DIM SHARED phone AS phonetype
CLS
phoneLen = LEN(phone)
OPEN "phone#.dat" FOR RANDOM AS #1 LEN = phoneLen
reader
INPUT "Do you want to add more? ", yn$
IF UCASE$(yn$) = "Y" THEN addfile
SUB addfile
CLS
INPUT "What is the name of the person you want to add? ", phone.FullName
INPUT "What is their phone number? ", phone.Number
PUT #1, , phone
END SUB
SUB reader
DO WHILE NOT EOF(1)
GET #1, , phone
PRINT phone.FullName, phone.Number
LOOPCLOSE #1
END SUB
much smaller!
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Posts: 4,307
Threads: 63
Joined: May 2003
The only way I think its possible is to copy the entire contents of the DB to another file exactly skipping the record that has to be deleted. Then delete old file and rename the new one. Also, what you could do is "mark" the records that have been deleted. When you shutdown the program, you do what I just said above. So all the records that have been deleted are physically removed from the file at once. Also you could implement a cool "roll-back" or "undo" feature because you dont physically delete any data until the program ends. You just hide it from the user
Posts: 199
Threads: 2
Joined: May 2003
I've breifly looked through your code. - A few things to note:
- Your add to file sub is going to overwrite any info you had in the file the last time the program was run.
If you see my code I have included Code: numContacts = LOF(1) / LEN(person)
This counts the amount of contacts there are in your phone book. LOF(1) is the length of your file (in bytes) LEN(person) is the length of your record (in bytes) therefor file length/record length = number of records
Also the put command is slightly different Code: PUT #1, numContacts+1, person
This adds a record onto the end of the file. You can see this in the code. numContacts is the total number of records, add 1 on and you have a new record to write to
- To erase data you would use a combination of find record (as shown in my previous code example) and add record. (you would basically add blanks to the record you wanted to erase)
Referring back to my code again. After finding a record the variable i is the number of the record that you have found. You could then just use Code: phone.fullname = ""
phone.number=""
PUT #1, i, phone
Hope this helps a little, I don't have time today to test or look through your code, but I'll try tomorrow.
You should try adding in a little menu system too.
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79] [/url]
END OF LINE .
Posts: 199
Threads: 2
Joined: May 2003
Quote:The only way I think its possible is to copy the entire contents of the DB to another file exactly skipping the record that has to be deleted. Then delete old file and rename the new one. Also, what you could do is "mark" the records that have been deleted. When you shutdown the program, you do what I just said above. So all the records that have been deleted are physically removed from the file at once. Also you could implement a cool "roll-back" or "undo" feature because you dont physically delete any data until the program ends. You just hide it from the user
I was going to mention this, but thought that may be a little too complicated for a newbie
@ Pyrokid: Is this a homework assignment?
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79] [/url]
END OF LINE .
Posts: 319
Threads: 68
Joined: Mar 2005
Well just to tell you the code works for adding new ones but dont ask me how just test it. And nope this isnt a homework assighment in fact my school doesnt even have a qbasic class the clossest thing it has to programming class is html publishing (which I plan on taking asap). haha i wish my school had a qbasic class that would be awsome!
oh yeah and creating a file like this:
Code: OPEN "C:\phone#.txt" FOR INPUT AS #1
It creates the file in the C:\ drive if C is your main drive otherwise it doesnt work. the reason mine didnt work is because PhoneNumber.txt is too long of a name otherwise it wouldve worked
his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Posts: 245
Threads: 48
Joined: Dec 2004
Pyro, you wouldn't happen to go to BHS, would you? You could just ask me (I'm also from Buffalo, and I am VERY dissapointed that there are no programming classes other than web page design).
I'm also very unfamiliar with RANDOM ACCESS files, and I've been confused with close to the same problem.
I can't figure this out:
Code: TYPE mytype
a AS STRING * 20
END TYPE
DIM mydim(1 TO 10) AS mytype
OPEN "file.txt" FOR INPUT AS #1
FOR C = 1 TO 10
INPUT #1, mydim(C).a
NEXT C
And getting it to end when the line ends, instead of counting it like this:
sampletext__________
With 10 spaces. End of line?
Posts: 199
Threads: 2
Joined: May 2003
The way random access file works means you have to specify the exact length of a record (and therefore the variables in the records)
A variable text$ could be any length.
A defined variable Code: DIM text AS STRING *10
is always going to be the same length. So: text="Hello" gets stored as "Hello_____"
There is a simple command for removing leading and trailing spaces. LTRIM$( var$) and RTRIM$( var$) (Left Trim and Right Trim)
N.B. you cannot do this:
Code: DIM text AS STRING * 10
text="Hello"
text=RTRIM$(text)
because text is still going to be 10 charecters long.
---
I know I said I'd go through your code today but work was busy, I had to go over my parents to get their broadband working again, and my girlfriend wanted me to watch Spiderman 2 with her I'm lucky I had any time on the computer
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79] [/url]
END OF LINE .
Posts: 4,307
Threads: 63
Joined: May 2003
Posts: 285
Threads: 70
Joined: Feb 2005
There is a PHONEDIR among the VARIOUS zip in my QB stuff at
http://sionet.mysite.wanadoo-members.co....QBASIC.htm
It also provides a sorted list of Numbers to take advantage of the UK free 1471 service which tells you the time and phone number of the last call if not being withheld. Alter the program to your taste.
Gordon
|