Click to See Complete Forum and Search --> : My own Database


deep2000
October 17th, 2001, 06:50 AM
Hello,

Can I create my own databse ?

seocndly

How can I save this information

Public Type Record
ID As Integer
Name As String * 20
End Type

Dim MyRec as Record

Myrec.Id=1
Myrec.name="deep"
How can I save this info to a file

Cimperiali
October 17th, 2001, 07:20 AM
option Explicit
'from msdn
'to test this, put two commandbutton on a form
private Type Record ' Define user-defined type.
ID as Integer
Name as string * 20
End Type

private Sub Command1_Click()
Dim MyRecord as Record, RecordNumber ' Declare variables.
' Open file for random access.
Open "c:\TESTFILE" for Random as #1 len = len(MyRecord)
for RecordNumber = 1 to 5 ' Loop 5 times.
MyRecord.ID = RecordNumber ' Define ID.
MyRecord.Name = "My Name" & RecordNumber ' Create a string.
Put #1, RecordNumber, MyRecord ' Write record to file.
next RecordNumber
Close #1 ' Close file.

End Sub

private Sub Command2_Click()
Dim MyRecord as Record, Position
Dim lentoread

Open "c:\TESTFILE" for Random Access Read as #1 len = len(MyRecord)
Do
Position = Position + 1
get #1, Position, MyRecord
If EOF(1) then Exit Do
me.print MyRecord.ID & " " & MyRecord.Name
Loop While EOF(1) = false

Close #1
End Sub

private Sub Form_Load()
Command1.Caption = "writedata"
Command2.Caption = "readData"
End Sub





Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater