Well, First let me give a little background on what my project does.
My company makes security systems. These systems have many different "modules" that perform different functions. One module is used as a entry point for access codes, another is used to connect alarm contacts, and so on. These modules can be connected up in many custom ways, but there are rules about how they can be connected. Along with the hardware component of our system, there is a custom software component that is generated based on how the hardware modules are connected together.
What my project does, is allows a user to "lay out" the hardware, makes sure that they follow the rules on the layout, and generates the custom software needed for that specific layout. Along the way it also allows them to print out a picture of the layout and connections ( a customized schematic diagram ), and wiring instructions for the system, and of course, save any layouts they have generated to a file.
1: As for the object references, what I have in my project are 16 different objects that represent the hardware "modules" of the security system. These are actually controls ( Command buttons ) that I create at run time and place on a worksheet ( a picture box ) that the user can scroll around. By dragging and dropping the buttons, they connect the various modules together ( lines are drawn on the picturebox to show these connections graphically ) These controls are pointed at by several arrays in my project.
What I did was take the name of the control, and its index, and make a string ( Control.Name & " " & Control.Index ) and placed this in the array that I wanted to save.
When I load the information back in, I loop through the array and look at each item. If it's a number I handle it separately, and if it's a string I use the Split function to extract the first whole word from the string. I use the SELECT structure to see if it matches one of my 16 possible control names, and if it does I recreate the reference with a SET statement at that point. If it does not match one of my control names, I know it's a regular string and just use it as normal.
2: All I used to ID the object reference was the name of the control.
3: I have a lot of arrays that are being used to hold the data on how the different modules are connected together, and the data for the custom software setup. This is pretty much the structure of these arrays:
23 two dimension arrays for software setups and control properties( SaveArrays() ).
2 one dimension arrays for storing objects held in two collections. ( SaveLineArray() and SaveControlArray() ).
1 one dimension array for saving all of my Index 0 control .tag properties. ( SaveTags() )
Plus a string ( DWZVersion ) that just saves the version of the data file, if I change the way the data is stored later.
I used an intermediate variant ( Item ) to store each of these arrays into a single dimension array.
' move the items into "BigSaveArray"
BigSaveArray(0) = DWZVersion
Item = SaveControlArray()
BigSaveArray(1) = Item
Item = SaveLineArray()
BigSaveArray(2) = Item
Item = SaveTags()
BigSaveArray(3) = Item
Item = SaveArrays()
BigSaveArray(4) = Item
'Then I move the entire "BigSaveArray" into the variant
Item = BigSaveArray()
FNum = FreeFile()
Open CD.FileName For Binary As #FNum
Put #FNum, , Item
Close #FNum
This writes the entire array to a file, and automatically stores all of the information that VB needs as far as the length of the data.
The reverse of the process reads a variant back out of the file, assigns it to the array ( which is a dynamic array ), and then I just pull the individual arrays back out of the "BigSaveArray".
Open CD.FileName For Binary As #FNum
Get #FNum, 1, Item
BigSaveArray() = Item
Close #FNum
' pull the other arrays out of "BigSaveArray"
DWZVersion = BigSaveArray(0)
Item = BigSaveArray(1)
SaveControlArray() = Item
Item = BigSaveArray(2)
SaveLineArray() = Item
Item = BigSaveArray(3)
SaveTags() = Item
Item = BigSaveArray(4)
SaveArrays() = Item
Then I pull the data as needed out of the arrays, reload all of the controls onto the worksheet, set their properties ( Left, top, height, width, caption, and a integer that points to an index in a ImageList control, to tell me what picture the control should have on it ), reset all of my references and recreate my collections.
And that's pretty much it. None of my strings are fixed size by the way.
Robert
![[peace] [peace] [peace]](/data/assets/smilies/peace.gif)