Question What is the best way to store a static table?

dHeather

Active member
Joined
Jun 18, 2012
Messages
27
Programming Experience
Beginner
Hello,

I have a static set of 163 files on a disc. These files fall into rough groups (11 in total). I need to display a single group in a ListView based on a users selection. There is overlap between the groups though so rather than seperating the files into folders on the disk and storing repeat files I would rather store them in a single folder and select the relevant files for any particular group.

So what I'm looking to create is a table that stores the file name and which of the 11 groups they are relevant to. This could be predefined if this is more efficient than creating it in runtime.

What I want to know is am I better off creating a static file that my program reads or am I better creating it in runtime, and in either instance which is the best solution? there seems to be all sorts of ways of storing data (Arrays, Dictionaries, Lists, ArrayLists and so on) and although I can find huge amounts of info on how to use each item I can find very little on what the best solution is for predefined data.

If someone can point me in the right direction that would be great.

Thanks
 
This is probably because there is no 'best' solution, as such. In this case, particularly, given the very small sample there is no great advantage to any method, although I would probably rule out creation of the table at runtime as there is overlap making a simple looping routine impossible. I'd probably go for a csv file to be read on form load, myself, but it really is up to you (and what requires least typing!)
 
There is no but, Serialization rules. :) Storing your data into multiple files is a bad idea IMO. Use the industry standard that is XML.

Dim myArrayList As New ArrayList

Public Sub New()
    myArrayList.Add("Element 1")
    myArrayList.Add("Element 2")
End Sub

Private Sub SerializeArrayList()
    Dim XmlSerializer As New XmlSerializer(GetType(myArrayList))
    Dim StreamWriter As New StreamWriter("C:\myArrayList.xml")
    
    XmlSerializer.Serialize(StreamWriter, myArrayList)
    StreamWriter.Close()
End Sub

Private Function DeSerializeArrayList() As ArrayList
    Dim XmlSerializer As New XmlSerializer(GetType(myArrayList))
    Dim FileStream As New FileStream("C:\myArrayList.xml", FileMode.Open)
    
    DeSerializeArrayList = CType(XmlSerializer.Deserialize(FileStream), ArrayList)
    FileStream.Close()
End Function
 
Back
Top