Solved

PropBag

Posted on 1998-04-08
19
235 Views
Last Modified: 2008-02-01
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.  
0
Comment
Question by:Pic
  • 7
  • 5
  • 2
  • +4
19 Comments
 
LVL 8

Expert Comment

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

0
 
LVL 1

Expert Comment

by:Anita030598
ID: 1460664
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
 
LVL 8

Expert Comment

by:mrmick
ID: 1460665
Anita, check out PropertyBag object in VB help.  Using the propertybag, you can do this without adding a listbox control.
0
 
LVL 1

Expert Comment

by:Anita030598
ID: 1460666
mrmick, thanks for that note. I will see that right away!
0
 

Author Comment

by:Pic
ID: 1460667
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
 
LVL 2

Expert Comment

by:vspeter
ID: 1460668
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
 
LVL 8

Expert Comment

by:mrmick
ID: 1460669
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
 

Author Comment

by:Pic
ID: 1460670
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
 
LVL 18

Expert Comment

by:deighton
ID: 1460671
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Pic
ID: 1460672
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
 
LVL 2

Expert Comment

by:marti
ID: 1460673
It's quite possible. But what you mean 'I need to use an array I created in design-time'?
0
 

Author Comment

by:Pic
ID: 1460674
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
 
LVL 2

Expert Comment

by:marti
ID: 1460675
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
 

Author Comment

by:Pic
ID: 1460676
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
 
LVL 2

Expert Comment

by:marti
ID: 1460677
The other way is to create property for every element of the array. Do you like it better?
0
 

Author Comment

by:Pic
ID: 1460678
marti, my array is a dynamic array. It is not fixed-sized array.

0
 
LVL 2

Expert Comment

by:marti
ID: 1460679
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
 

Author Comment

by:Pic
ID: 1460680
marti, if that is the case, so be it. You can lock on, I will give you the point.
0
 
LVL 2

Accepted Solution

by:
marti earned 50 total points
ID: 1460681
Thank you Pic
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now