decrypt Posted January 2, 2004 Posted January 2, 2004 I'm trying to make an address book. I've tried alot of things and still no luck. Anybody got any ideas? Quote
sizer Posted January 2, 2004 Posted January 2, 2004 and the problem is..? Quote Some people are wise and some are other-wise.
iebidan Posted January 2, 2004 Posted January 2, 2004 well, I think he's asking for any ideas on creating an address book :) How about using XML for the address book?? something like <addressbook> <contact> <name>A NAME HERE</name> <address>AN ADDRESS HERE</address> </contact> </addressbook> What you think about it???? Quote Fat kids are harder to kidnap
decrypt Posted January 2, 2004 Author Posted January 2, 2004 (edited) well i was wondering if you can make a sort of thing like in windows explorer when you do view-detials. Can a regular listbox be split up into 5 different sections? E.g. Listbox: __________________________________________________ |collum1 | collum 2 | collum 3 | collum 4 | collum 5| | Data 1 | data 2 | data 3 | data 4 | data 5 |__________________________________________________ Edited January 2, 2004 by decrypt Quote
*Experts* DiverDan Posted January 2, 2004 *Experts* Posted January 2, 2004 Try looking into a ListView or a DataGrid control. They'll probably better suit your needs. You can also easily serialize the items in these controls for saving to disk. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
decrypt Posted January 2, 2004 Author Posted January 2, 2004 Ok i got it now. How would you save it? Quote
Administrators PlausiblyDamp Posted January 2, 2004 Administrators Posted January 2, 2004 You may want to look at the Xml.Serialization.XmlSerializer class. There are a couple of pretty good samples on how to use it in MSDN. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
decrypt Posted January 2, 2004 Author Posted January 2, 2004 Ok I looked that up and I got this, but I do not know what to change in it. :confused: Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim myObject As MySerializableClass = New MySerializableClass ' Insert code to set properties and fields of the object. Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(MySerializableClass)) ' To write to a file, create a StreamWriter object. Dim myWriter As StreamWriter = New StreamWriter("contacts.xml") mySerializer.Serialize(myWriter, myObject) End Sub I get the squigily line under the following: MySerializableClass, XmlSerializer, and StreamWriter. It says that they are not defined. Quote
*Experts* Bucky Posted January 2, 2004 *Experts* Posted January 2, 2004 MySerializableClass needs to be the class that has a collection of all your contacts. As for the other squiggly lines, you need to import the namespaces System.IO and System.Xml.Serialization Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
decrypt Posted January 2, 2004 Author Posted January 2, 2004 (edited) Thanks alot, but I don't know which MySerializableClass needs to be changed the first and the second. And I still don't understand which one. Dim myObject As MySerializableClass = New MySerializableClass would it be the datagrid or the xml file? Edit: Well? Edited January 2, 2004 by decrypt Quote
*Experts* Bucky Posted January 2, 2004 *Experts* Posted January 2, 2004 It's a class that is a collection of your address book contacts. So, for example, you first create a class that stores all the address information, like so: Public Class Contact ' Private members of the class Private m_FirstName As String Private m_LastName As String ' Public properties that are saved in the XML file Public Property FirstName() As String Get Return m_FirstName End Get Set(Value As String) m_FirstName = Value End Set End Property Public Property LastName() As String Get Return m_LastName End Get Set(Value As String) m_LastName = Value End Set End Property End Class Then make a collection, add some contacts, and serialize it: Dim contacts As New ArrayList() Dim person As New Contact() person.FirstName = "Bucky" person.LastName = "Fuller" contacts.Add(person) Now the contacts variable is the substitution for MySerializableClass. You don't need to initialize it again, because it's already done in the above code. Just serialize it. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
decrypt Posted January 3, 2004 Author Posted January 3, 2004 I did that using an xml file though.... Quote
*Experts* Bucky Posted January 3, 2004 *Experts* Posted January 3, 2004 I don't understand, you did what? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
decrypt Posted January 3, 2004 Author Posted January 3, 2004 (edited) Ok i'll start from the begining. First I made an xml file that included this: <addressbook> <contact> <name>A NAME HERE</name> <address>AN ADDRESS HERE</address> </contact> </addressbook> Then I did this so that a DataGrid would display it. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dsUsers As New DataSet dsUsers.ReadXml("..\contacts.xml") With Contactsgrid .CaptionText = "Your Contacts" .DataSource = dsUsers.Tables(0) End With End Sub now i'm trying to serialize it using this code: Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim myObject As MySerializableClass = New MySerializableClass ' Insert code to set properties and fields of the object. Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(MySerializableClass)) ' To write to a file, create a StreamWriter object. Dim myWriter As StreamWriter = New StreamWriter("contacts.xml") mySerializer.Serialize(myWriter, myObject) End Sub Edit: Well? Edited January 3, 2004 by decrypt Quote
*Experts* Bucky Posted January 3, 2004 *Experts* Posted January 3, 2004 Oh, heh. You don't need to serialize it this way. The DataSet can serialize the data itself by using the WriteXml method. That's all you need to do, just call dsUsers.WriteXml() with a file path. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
dotnetgirl Posted January 6, 2004 Posted January 6, 2004 what if .. Hello decrypt, What if the values are coming from multiple forms? I mean if user fills in fields on multiple forms, can we use only one class to serialize on all forms giving some of the entries only? Pl. Reply Regards. Quote
decrypt Posted January 10, 2004 Author Posted January 10, 2004 the dsUsers.WriteXml("path") should serialize all of the fields in the xml file. The xml file should be created by yourself. Be sure to not declare dsUsers in a sub, so that you can save it and load it in different subs. This is what i did: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dsUsers.ReadXml("contacts.xml") With Contactsgrid .CaptionText = "Your Contacts" .DataSource = dsUsers.Tables(0) End With End Sub For Loading and.... Private Sub Button1_Click (whatever goes in here which i cant remember) DsUsers.WriteXml("contacts.xml") End Sub To save and... Dim dsUsers As New DataSet Does this answer your question? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.