Page 1 of 1
How to Write Record into a file?
Posted: Fri Jul 22, 2011 5:48 pm
by Manolo
I tried to write a minimal record into a file but I got just Errors.
Is there someone that can explain me how do it? :(
Tnx.
How to Write Record into a file?
Posted: Fri Jul 22, 2011 7:50 pm
by Marco
I hope this will help you,best regards:
record car
? wheel as integer
? mirror as string
end record
`put som data in it
car.wheel=10
car.mirror="good"
`declare and open filestream
dim data as filestream
data.open("test.txt")
`write data
data.write(car)
``close file
data.close
How to Write Record into a file?
Posted: Sat Jul 23, 2011 8:05 am
by Manolo
Hooo tnx a lot Marco...
I tried with RANDOMFILE but it is the wrong way probably.
but... how works RANDOMFILE?
How to Write Record into a file?
Posted: Sat Jul 23, 2011 3:56 pm
by Marco
yes, forgot the powerfull randomfile,
here`s an example of it
you can address the records by a number and read and write whole records at once. I think this is preferable.
here`s some sample code to experiment with it.
best regards
`==========set it up============
record car
wheel as integer
color as string * 10
end record
dim dbase as randomfile
`open file this before assigning the record
dbase.open("database.txt")
`assign record
dbase.assign(car)
`===============================
`put some data
car.wheel=10
car.color="red"
`append to file
dbase.append
`==========check the results====
car.wheel=0
car.color=""
`read record 1 yuo can also write a record with put
dbase.get(1)
showmessage "found "+car.color+str$(car.wheel)
`===============================
How to Write Record into a file?
Posted: Thu Dec 01, 2011 5:07 am
by Cage
I just recently downloaded the newest version of FNX and discovered a really good programing tool.? Being a VB programer for years, I was looking for a good tool to replace it since VB no longer is supported.? I have a bunch of programing tools, but FNX is quickly turning into my favorite.? Basically with the addition of the RANDOMFILE FNX has become a viable programing tool for me.? ?My thanks to YaBB for his basics in using the random file made my transition much easier.? ?After one evening of playing with his example I had figured out all the random file commands.? ?Thank you Yabb? :)
Hope you don`t mind me posting the expanded version.
`*********************RANDOM FILE ********************
`This program explains the basics for use of the random
`file method.? ?It`s not a complete program on all the
`differnt methods of using a random database but it will
`get you started.?
Dim a as INTEGER,i as INTEGER
`First set up the record varibles.?
`In other basics they used the TYPE
`and END TYPE.? Works the same just
`called record instead.
record car
? wheel as string *6
? color as string * 10
end record
`Assign a name to the random file
`in this case we will call it dbase
dim dbase as randomfile
`open file before assigning a record
`Give the Database a name in this case
`I`ll call it DATABASE.DBF (DBF=Data Base File)
dbase.open("database.dbf")
`Assign the record called car to the database
dbase.assign(car)
`Assign some data to place in the dbase record file
car.wheel="10"
car.color="red"
`Note: Records in the database always start
`with 0, so the first record wour be 0
`Now put the information to record 0
dbase.put(0)
`Clear the car data for next record
car.wheel=""
car.color=""
`Assign some data for the next record
car.wheel="1"
car.color="blue"
`Put the information into the next record 1
dbase.put(1)
`Now we will sort the records to put
`them in order using car.wheel.
dbase.Sortfields(car.wheel)
How to Write Record into a file?
Posted: Thu Dec 01, 2011 5:08 am
by Cage
This is the second half.
`Before you read back the data, get the number of
`records in the database. Assign this number to
`a varible, in this case a
a=dbase.records
`Now print the number of records
Print "Number of Records ";a
`Set the pointer i to equal 0
i=0
`Now get and display the records.
`While i (pointer) is less then
`the number of records in a
While i<a
`Clear the varibles for car
car.wheel=""
car.color=""
`Now get the records in the database and display them
dbase.get(i)
Print "Record: ";i;"? Wheel: "; car.wheel; " Color: ";car.color
i=i+1
Wend
Print
Print
Print
Print
`Now I will swap the records back to the
`way they were entered originally.
`Swapping record 1 with record 0.
`This is a good method to fill in the
`gaps in your database
dbase.Swaprec(1,0)
`Set the pointer I to equal 0
i=0
`Now get and display the records.
While i<a
`Clear the varibles for car
car.wheel=""
car.color=""
`Now get the records in the database and display them
dbase.get(i)
Print "Record: ";i;"? Wheel: "; car.wheel; " Color: ";car.color
i=i+1
Wend
Print "dbase is closed"
`Close the database
dbase.Close
`Wait for a key press to end program
Print
Print "Press a key"
While inkey$="":wend
`===============================
`Us the delete command to delete records
`dbase.Delete(recordnumber)
`Note: information in the record will be
`deleted not the actual record. The
`record will just be a blank.
`To insert new data to a blank record
`use the following command.
`dbase.Insert(recordnumber)
`you would scan the records to find the empty
`record, and use the record number found to
`inset the new data.