Array Help!?!?!?...

J

JB

OK Folks Help required....I just can't seem to think this through.

I have 7 toolbars, in each of the toolbars there are between 9 and 14
controls. For each of the controls I want to extract data which may be
up to 22 items.

How the hell can I do this using an array/arrays???

I've tried to do this using dynamic arrays but with no success.

Any pointers??

Cheers
J
 
P

Peter

JB said:
OK Folks Help required....I just can't seem to think this through.

I have 7 toolbars, in each of the toolbars there are between 9 and 14
controls. For each of the controls I want to extract data which may be
up to 22 items.

How the hell can I do this using an array/arrays???

I've tried to do this using dynamic arrays but with no success.

Any pointers??

Cheers
J

No, no pointers: this is a VBA newsgroup, not a C/C++ newsgroup. ;-)

I wouldn't recommend using arrays at all. Rather, either create your own objects to store the data using VBA classes (the best solution), or use collections, like so:

Sub SaveCommandBars()
Dim CmdBar As CommandBar
Dim Control As CommandBarControl
Dim Toolbars As Collection
Dim Toolbar As Collection

Set Toolbars = New Collection
For Each CmdBar In Application.CommandBars
If CmdBar.BuiltIn = False Then
Set Toolbar = New Collection
For Each Control In CmdBar.Controls
Call Toolbar.Add(Control.Application, "Application")
'... add all the other items you want
Next Control

Call Toolbars.Add(Toolbar, CmdBar.Name)
End If
Next CmdBar
End Sub

I'm adding each property explicitly because I don't know of a way to iterate through a Control's properties; but I'm sure it can be done somehow, possibly by casting it to some generic type. Or perhaps that's the Java in me speaking.

Referencing your previous posts, if the purpose of this is to add the info to an ini file, perhaps you should forget storing the information and just create the ini file as you iterate through the controls.

-Peter
 
J

Jezebel

I'm adding each property explicitly because I don't know of a way to
iterate through a Control's properties; but I'm sure it can be done somehow,
possibly by casting it to some generic type. Or perhaps that's the Java in
me speaking.

Sadly, there usually isn't a direct way to do this. There's an API method;
and at some point there was obviously a push at Microsoft that objects
should always include a Properties collection precisely for this purpose.
Some objects have it but most don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top