saving & retreiving VB6

Hi there everyone,

I have been trying to use the Commondialog control to save information from a textbox and retrieve it at some point but the problem is, I can't seem to retrieve more than the variables a,b,c,d which were originally programmed to save as "Name", "LastName", "Phone" and "Coutry". Can someone please advice me on how to save more than just these four properties? Code included below. Thanks:-

Private Sub Save_Click()
' The data stored will be saved as variant
Dim varTemp As Variant
' This is if the user press the cancel button.
On Error GoTo errhandler

CommonDialog1.ShowSave

' Create new property bag.
Set pb = New PropertyBag

' We save the text in the property bag and give a
' name to every string.
pb.WriteProperty "Name", txtName.Text
pb.WriteProperty "Payroll Number", txtPayroll.Text
pb.WriteProperty "Address", txtAddress.Text
pb.WriteProperty "Department", cboSelect.Text
pb.WriteProperty "Claim", txtClaim.Text
pb.WriteProperty "Hours Wrk", Form2.txthrsWorked.Text
pb.WriteProperty "Hourly Rate", Form2.txthrrate.Text
pb.WriteProperty "Total", Form2.txttotal.Text

' We convert the propertybag contents to variant.
varTemp = pb.Contents

' Now we open a file, save the data and put it a name
' (With the common dialog).
Open CommonDialog1.FileName For Binary As #1
Put #1, , varTemp
Close #1

' If user pressed cancel button exit sub.
errhandler:
Exit Sub
End Sub


Private Sub Open_Click()
Dim varTemp As Variant
Dim byteArr() As Byte
' This is necesary to convert from Variant to Byte.
' If you dont do that,the data will not be visible in
' the text boxes.

On Error GoTo errhandler

CommonDialog1.ShowOpen

Set pb = New PropertyBag

'Open the file and store the data in a variable
Open CommonDialog1.FileName For Binary As #1
Get #1, , varTemp
Close #1

' Convert the variant to byte.
byteArr = varTemp
' Property bag contents as byte.
pb.Contents = byteArr

' Store the read data to a variable.
a = pb.ReadProperty("Name")
b = pb.ReadProperty("Payroll Number")
c = pb.ReadProperty("Address")
d = pb.ReadProperty("Department")
e = pb.ReadProperty("Claim")
f = pb.ReadProperty("Hours Wrk")
g = pb.ReadProperty("Hourly Rate")
h = pb.ReadProperty("Total")

' Now put the value of the variables in textboxes
txtName.Text = a
txtPayroll.Text = b
txtAddress.Text = c
cboSelect.Text = d
txtClaim.Text = e
Form2.txthrsWorked.Text = f
Form2.txthrrate.Text = g
Form2.txttotal.Text = h
errhandler:
Exit Sub
End Sub

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories