Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
database saving prob
#1
look at the code, i cant get the program to save the inpout so it is still there after you exit the program.
Code:
top:
CLS
PRINT "DATABASE"
PRINT " "
PRINT "1) Enter name and adress into database"
PRINT "2) View database"
PRINT "3) Exit"
PRINT " "
PRINT " "
INPUT "What would you like to do"; mmchc$
  IF mmchc$ = "1" THEN GOTO enterbase:
  IF mmchc$ = "2" THEN GOTO viewbase
  IF mmchc$ = "3" THEN END

enterbase:
  TYPE people
        nm AS STRING * 40
        age AS INTEGER
        address AS STRING * 60
  END TYPE
DIM person AS people
OPEN "fileprog.dat" FOR RANDOM AS #1 LEN = LEN(person)
INPUT "Record"; record
INPUT "Name: "; person.nm
INPUT "Age"; person.age
INPUT "Address:"; person.address
PUT 1, record, person
CLOSE

GOTO top

viewbase:
CLS
INPUT "View which record"; record
GET 1, record, person

  

  PRINT "Name: "; person.nm
  PRINT "Age: "; person.age
  PRINT "Address: "; person.address
  CLOSE
  END

anything would be nice
unning a panasonic toughbook, cf-25 Smile
Reply
#2
Just at a glance I noticed these things:
First, you didn't place the "type" info. at the beginning of the program. That would be a good place to start.
Second, you're asking it to "put" person as opposed to person.nm
Third, you placed the "len" statement before you actually have a "person" to measure (if you will).
I don't know if this last one "len" will make a difference or not as I've never placed it anywhere except after the object to be "measured" has been entered.
I also don't use the "type" command very often to say if that will have any effect or not. I have a feeling it will though.
There's probably more, but those are the things I noticed just glancing at it.
Hope this helps. :wink:
adsherm
Reply
#3
You should have your "TYPE people" and "DIM person" statements near the beginning of the main program, not in a sub routine. The user may choose to view to the data base first, and person will have to be dimensioned to set the record size when you open the file.

In viewbase, you try to read the file you haven't opened it first.

I don't see a problem with your program saving a file (though generally you won't prompt the user for the record number)

Also, instead of using 1 for the filenumber, it is a good idea to use FREEFILE. When you are only using one file, it doesn't really matter, but using varibles allows you to write procedures that can handle different files.
Code:
FileNum = FreeFile
FileName$ = "MyDataFile.dat"
OPEN FileName$ FOR RANDOM AS FileNum LEN = LEN (Person)
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)