Discussion Locked

Save time with control arrays

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

This week's Visual Basic e-newsletter describes how you can save time with control arrays.

Do control arrays save you time in your programming work? Is this tip useful to you? What topics would you like us to cover in future editions of this e-newsletter? Please let us know.

If you aren't subscribed to our free Visual Basic e-newsletter, click the following link to automatically sign up:
http://nl.com.com/MiniFormHandler?brand=builder&subs_channel=bldr_front_door&list_id=e065&tag=fb

4 replies

by rayt

Control arrays save us much time I would like to see more help with printing. Our company does accounting applications and we have to use preprinted forms. We are using Active Reports and VB6. Any help on these lines would be appreciated.

by setivi

Great Job Peter Aitken on the Control Arrays. This concept had been a myth to me. But your explanation of the topic turned the lights on for me. I now feel very comfortable using the concept.

Please shed some light on populating DataCombo by scripts/codes in conjunction with ADO as the interface to SQL tables.

Keep up the good work.

Seth Nyenya

by pimpernel

I've used Control arrays for years, including quite recently, however, finding out that VB.Net does not support them has made me have a re think in view of the fact that we could soon be upgrading.

by jeff_d_programmer

While control arrays can be useful for keeping blocks or code together, they have two major drawbacks:
1. They break the cardinal rule of procedures and functions - a process should only encompass one piece of functionality. If it must do more, break it into discreet pieces and separate them out into separate functions. By breaking this rule you make your code more difficult to read, less reusable, and more difficult to modify (a change to a block of code is much more likely to have unintended consequences).
2. They do not upgrade to VB.Net, nor are they available in most other languages, thus making them impossible to port or upgrade.

Microsoft VB Wizards creates them in only one instance - the buttons on a toolbar - and this is only because an individual button on a toolbar does not raise its own event. Even then you should call out to a separate procedure for the actual functionality of the action. Example:

Private Sub tbToolBar_ButtonClick(ByVal Button As MSComCtlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "New"
Call Create_New()
Case "Open"
Call mnuFileOpen_Click
Case "Save"
Call mnuFileSave_Click
Case "Print"
Call mnuFilePrint_Click
Case "Cut"
Call mnuEditCut_Click
Case "Copy"
Call mnuEditCopy_Click
Case "Paste"
Call mnuEditPaste_Click
End Select
End Sub

Thus you can see that using control arrays is actually a bastardization of the select case statement. If you feel you MUST use it, use it sparingly and give plenty of fore-thought as to WHY your overriding the most basic of programming principles.

This discussion is closed to new replies.