Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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????

Fat kids are harder to kidnap
Posted (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 by decrypt
  • *Experts*
Posted
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.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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.

  • *Experts*
Posted

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted (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 by decrypt
  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted
I don't understand, you did what?

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted (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 by decrypt
  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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.

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...