How to use Deserialized output?

E

Ed Bitzer

Obviously a newbie to vb.net and attempting to read an arraylist and then
use. No problem outputting and Serializing but, and the dumb question - how
to I extract something from the obj retrieved below (which debug shows has
values for the Person structure) and place in a text box?

Appreciate, Ed

<Serializable()> Public Structure Person
Dim Name As String
Dim Age As Integer
Dim Income As Decimal
End Structure

Public Sub btnReadArray_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReadArray.Click
Dim FS As New System.IO.FileStream("c\test.txt",
IO.FileMode.OpenOrCreate)
Dim obj As Object
Dim Persons As New ArrayList
Dim P As Person
Dim BinFormatter As New Binary.BinaryFormatter
obj = CType(BinFormatter.Deserialize(FS), ArrayList)
 
G

Guest

Jan. 10, 2005

Try:

Dim FS As New System.IO.FileStream("c\test.txt",
IO.FileMode.OpenOrCreate)
Dim obj As Object
Dim Persons As ArrayList ' Change from As New to As
Dim P As Person
Dim BinFormatter As New Binary.BinaryFormatter
Persons = CType(BinFormatter.Deserialize(FS), ArrayList) 'Change to
Persons
for each obj in persons
P = Ctype(obj, person)
textbox1.text = P.Name
next

Then change the specific use of each Person object to match your
needs. I didn't test this, but it looks like it should work! :)


Joseph MCAD
 
E

Ed Bitzer

I thank you Joseph, got it working.. I use to program in Pascal and was
use to creating custom types such as name, age, income but here it is
obvious I am just learning. I find that I can reference the individual
items in the array once "reconstituted" using TextBox1.Text =
Persons(0).Name and Person(2). age. I suspect the simpler way might have
been to use a multidimensional array.

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top