Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
How to save data from different textboxes in the s...
Author:
Caesar Ornelas
E-mail:
Click to e-mail author
Submitted:
1/20/2001
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
16847
How to save data from different textboxes in the same file.
Declarations:
'none
Code:
This is an example of how to save data from different textboxes in the same file. We need 4 textboxes, 3 buttons and a commondialog control. Use the text boxes to store some data like name,last name, phone and country. Name the buttons open, save and clear. Declare some private variables (Used at module level to declare private variables and allocate storage space). ' Declare a PropertyBag object. Private pb As PropertyBag ' This strings will represent the text boxes. Private a As String Private b As String Private c As String Private d As String Saving the data... Here we create a property bag to store the data and save the data of the textboxes as variant in a file. 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", Text1.Text pb.WriteProperty "LastName", Text2.Text pb.WriteProperty "Phone", Text3.Text pb.WriteProperty "Country", Text4.Text ' We convert the propertybag contents to variant. varTemp = pb.Contents ' Now we open a file, save the data and put it a name ' (Whit the common dialog). Open CommonDialog1.FileName For Binary As #1 Put #1, , varTemp Close #1 ' If user pressed cancel buton exit sub. errhandler: Exit Sub End Sub To open the data saved... Here we open the file, we convert the variant data to byte and read the data from a property bag, then we store the data in the textboxes. 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("LastName") c = pb.ReadProperty("Phone") d = pb.ReadProperty("Country") ' Now put the value of the variables in textboxes Text1.Text = a Text2.Text = b Text3.Text = c Text4.Text = d errhandler: Exit Sub End Sub ' Clear the contents of the text boxes Private Sub Clear_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement