General discussion

  • Creator
  • #2274243

    Save time with control arrays


    by maryweilage ·

    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:

All Comments

  • Author
    • #2701564

      Use of Control Arrays

      by rayt ·

      In reply to Save time with control arrays

      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.

    • #2701507

      Control Arrays

      by setivi ·

      In reply to Save time with control arrays

      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

    • #2701281

      VB6 Control Arrays

      by pimpernel ·

      In reply to Save time with control arrays

      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.

    • #2701278

      Use sparingly!

      by jeff_d_programmer ·

      In reply to Save time with control arrays

      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.

Viewing 3 reply threads