|
Option Explicit
Private m_strFileName As String
Private t0 As String, t1 As String, t2 As String
Private t3 As String, t4 As String
Private c1 As String
Private Sub Form_Load()
t0 = "Nachname"
t1 = "Vorname"
t2 = "Ort"
t3 = "Straße"
t4 = "eMail"
c1 = chkBox.Caption
m_strFileName = GetDATFileName
Call GetFormData
End Sub
Private Function GetDATFileName() As String
Const cFileName As String = "pb.dat"
Dim strPath As String
strPath = App.Path
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
GetDATFileName = strPath & cFileName
End Function
Private Sub GetFormData()
Dim FN As Integer
Dim pb As PropertyBag
Dim varPB As Variant
On Error Resume Next
If Len(Dir(m_strFileName, vbNormal)) <> 0 Then
FN = FreeFile()
Open m_strFileName For Binary As #FN
Get #FN, , varPB
Close #FN
Set pb = New PropertyBag
pb.Contents = varPB
txtFeld(0).Text = pb.ReadProperty(t0, "Nachname")
txtFeld(1).Text = pb.ReadProperty(t1, "Vorname")
txtFeld(2).Text = pb.ReadProperty(t2, "Wohnort")
txtFeld(3).Text = pb.ReadProperty(t3, "Straße")
txtFeld(4).Text = pb.ReadProperty(t4, "eMail")
chkBox.Value = pb.ReadProperty(c1, "1")
End If
On Error GoTo 0
End Sub
Private Sub SaveFormData()
Dim FN As Integer
Dim pb As PropertyBag
Set pb = New PropertyBag
pb.WriteProperty t0, txtFeld(0).Text
pb.WriteProperty t1, txtFeld(1).Text
pb.WriteProperty t2, txtFeld(2).Text
pb.WriteProperty t3, txtFeld(3).Text
pb.WriteProperty t4, txtFeld(4).Text
pb.WriteProperty c1, chkBox.Value
FN = FreeFile()
Open m_strFileName For Binary As #FN
Put #FN, , pb.Contents
Close #FN
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SaveFormData
End Sub
|
|