By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,138 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Persisting fixed data

P: n/a
I'm stretching my fairly elementary vb.net experience by trying to
write a report generator for a specialised utility. The report will
contain a simple tabular output, but there could be up to 100 or more
column types from which the user can choose to include on a specific
report and each type may have eg 10 attributes: name, value, width,
formatting etc etc

All the types and attributes are known at design time and could be
used to populate eg a structure array, though there obviously are
other alternatives.

But the question is about how best to persist this data. I don't
really want to assign the attributes one at a time, ie one line of
code per attribute, because that would create 1000 lines of code or
more and be pretty cumbersome to maintain. But equally it would be
nice to avoid a more structured solution such as eg an external
database that could bloat the program. In fact being able to embed the
data within the main assembly would seem to be a more elegant
solution, but I guess simplicity is more important than elegance.

Anyone have any advice please, bearing in mind that I'm not an expert
vb.net user.

Thanks
JGD
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you create a class called "columntype", containing your attributes - you
can populate an array of column types and output them to an XML file with a
single loop. Simple example below, that doesn't fill in many of the blanks:
class myColumnType

private m_Name as String
private m_Value as Object
private m_Width as integer

public sub WriteXML (theNode as XmlNode)
...
... write my attributes to the xml tree
...
end sub

public sub ReadXML (theNode as XmlNode)
...
... read my attributes from the xml tree
...
end sub

end class
private m_Array as New ArrayList

m_Array.Add ( new MyColumnType ( bla bla bla ) )
m_Array.Add ( new MyColumnType ( foo foo foo ) )

for each theColumn as MyColumnType In m_Array
theColumn.WriteXML ( theXMLDocument)
Next
"John Dann" <ne**@prodata.co.uk> wrote in message
news:8i********************************@4ax.com...
I'm stretching my fairly elementary vb.net experience by trying to
write a report generator for a specialised utility. The report will
contain a simple tabular output, but there could be up to 100 or more
column types from which the user can choose to include on a specific
report and each type may have eg 10 attributes: name, value, width,
formatting etc etc

All the types and attributes are known at design time and could be
used to populate eg a structure array, though there obviously are
other alternatives.

But the question is about how best to persist this data. I don't
really want to assign the attributes one at a time, ie one line of
code per attribute, because that would create 1000 lines of code or
more and be pretty cumbersome to maintain. But equally it would be
nice to avoid a more structured solution such as eg an external
database that could bloat the program. In fact being able to embed the
data within the main assembly would seem to be a more elegant
solution, but I guess simplicity is more important than elegance.

Anyone have any advice please, bearing in mind that I'm not an expert
vb.net user.

Thanks
JGD

Nov 21 '05 #2

P: n/a
Serialize the data to a stream... the basics are pretty easy
0) decorate your class with <Serializable()>
1) create a stream: Dim fstream As New FileStream("MyFile.bin",
FileMode.Create, FileAccess.Write, FileShare.None)
2) create a formatter: Dim bf as New BinaryFormatter()
3) serialize: bf.Serialize(fstream,YourClass)
4) clean-up: fstream.Close()

there are some special consideration about the deserialization -- you
will need a special class constructor... the .NET Framework will
serialize an object graph (i.e. it will serialize objects within your
object).

here are some links -- the first has a demo...
Object Serialization in Visual Basic .NET (Adventures in .NET)
http://msdn.microsoft.com/library/en...asp?frame=true

Serializing Objects (.NET Framework Developer's Guide)
http://msdn.microsoft.com/library/en...asp?frame=true

good links to related topics here...
Binary Serialization (.NET Framework Developer's Guide)
http://msdn.microsoft.com/library/en...asp?frame=true

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.