PropBag

How to store the content of an array to and fore design-time and run-time. ProBag?
I need to use an array I created in design-time during run-time. And after that, when switch back to
design-time, I still need that array. How do I preserve the array during the transition.  
PicAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kobe_LenjouCommented:
What are you exacly trying to do????
Can't you hardcode the array, put it in a data file, a database?

0
Anita030598Commented:
How big is your array? If you have a form in your application, you can  add a listbox to it and store your array elements as list items in it. Use the List property. You can hide the list box as well. During run time, you can use the list box as it is to get the array item (list items) or put the items in an array or collection object.

BTW, what's ProBag? New terminology for me.
0
mrmickCommented:
Anita, check out PropertyBag object in VB help.  Using the propertybag, you can do this without adding a listbox control.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Anita030598Commented:
mrmick, thanks for that note. I will see that right away!
0
PicAuthor Commented:
mrmick, I think you are in a better position to help me.
How do I use the PropBag on an Array for the Q I mentioned?.
0
vspeterCommented:
I don't think that you can preserve the array at design time. Using the ReadProperty and WriteProperty method, you can save the info into the 'Cookie'

Cheers
0
mrmickCommented:
vspeter, please don't lock questions without providing a solution.  This question has nothing to do with cookies - cookies are something a webserver passes to a connected client for identification purposes.  Cookies have nothing to do with arrays or saving data.

pic, the propertybag object isn't what you want.  This is designed to be used when creating an ActiveX control.  When an ActiveX control is placed on a form it is instantiated and is then "running"; thus, properties become available and you can make additions/changes.  These changes are actually read/written in the UserControl_ReadProperties and  UserControl_WriteProperties event procedures.  This wouldn't work in an app because there's no "running code" to cause the data to be saved until you actually run the app.

Probably your best bet is to dimension an array in the declarations section of the form/module (module using public if you want global scope) and populate it in the Form_Load event procedure.  For example, if you had an array titled Colors, you could populate it in the Form_Load event procedure as follows...

Colors(0) = "Red"
Colors(1) = "Blue"
etc...

If you don’t like this suggestion, you could write your own UserControl (aka ActiveX control) just for this purpose; however, if this is the path you choose, I recommend you take Anita’s suggested solution since the listbox would serve this purpose.

Whatever you do, I hope you reject vspeter's proposed answer.
0
PicAuthor Commented:
mrmick, sorry that I didn't mention this - I am builting an ActiveX control!
During design time in the initproperties event, my control will loop through all
controls on the form, any editbox found will be stored into an array. The control also
has a property page that allow one of the editbox in the array to be selected. The selected editbox will be used during run-time for this control to "talk" to.
All the above is already written and tested.
Now, when switched back to design time, as you know, the array is no longer there.
What happen if the user using my control want to reselect another editbox?  
This is where my Q comes in. I need to preserve that array somehow.
I think PropBag may do, but I don't know how to create the property for the array and how to use the propbag in read and write properties event.
Or how do I use the listbox? please explan. you did say that I don't need it.

0
deightonprogCommented:
The contents of arrays are effectively discarded once a program has ended.  Files are used to store data in a more permanent form on your storage device.

One solution is to write the array contents to disk using a fuction and reading it back from the file when you re-run the program. example

private sub WriteArray(ByRef MyArray())

'Function to read values back from a temporary file. You will call this function at design 'time to store your array values to a text file.
'You need to send the

dim i as integer
open "c:\temp\array.txt" for output as #1
for i = LBound(MyArray) to UBound(MyArray)
  write #1,MyArray(i)
next
close #1,

end sub

private sub ReadArray(ByRef MyArray())

'Function to store array values in a temporary file
'In your finished application you will be able to restore the values to the array.

dim i as integer
open "c:\temp\array.txt" for output as #1
for i = LBound(MyArray) to UBound(iArrayUpper)
  input #1,MyArray(i)
next
close #1,

end sub

 
0
PicAuthor Commented:
deighton, sorry, I would prefer not to use a file for storage of array content.
My idea is to use the propbag, if it is possible. mrmick did say it can be done.
0
martiCommented:
It's quite possible. But what you mean 'I need to use an array I created in design-time'?
0
PicAuthor Commented:
marti, just assume that I store some data into the array at design-time which I need to use later when I switch from design-time to run-time, then back to design-time.
I thought I explained it clearly when I talked about the ActiveX control that I am building.

0
martiCommented:
Well. Create a property say 'Array'. Whenever you change your array at design time create a string which has this format:
1. Number of rows & separator
2. Number of cols & separator
3. List all the members of the array delimited with separator
Set 'Array' property equal to this string.
When you switch to run time this string will be saved at WriteProperties event.
So at run time when ReadProperties fires you have to populate that string back to the array.
And that's it. Hope this is what you are looking for.
Regards.
0
PicAuthor Commented:
marti, your answer is actually what I have done in the past.
Right now, I am looking for a way to preserve the array without
bothering about constructing it into a string and then separate it back later.
Does antone know how I can do this using the PropBag?




0
martiCommented:
The other way is to create property for every element of the array. Do you like it better?
0
PicAuthor Commented:
marti, my array is a dynamic array. It is not fixed-sized array.

0
martiCommented:
So in this case I don't think you have option other then assembling your dynamic array into a sting. Read Write PropBag events are invoked only per properties.
0
PicAuthor Commented:
marti, if that is the case, so be it. You can lock on, I will give you the point.
0
martiCommented:
Thank you Pic
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.