Control array, Visual Basic Programming

CONTROL ARRAY

The control array is a group of similar objects with similar name. Adding controls with control arrays uses less resource than simply adding the multiple controls of similar type to a form at the design time. The Control arrays are also helpful if you want some controls to share the code. For illustration, if 3option buttons are formed as a control array, the similar code is executed in spite of which the button was clicked.

If you desire to create a new instance of a control at the run time, that control should be a member of the control array. Through a control array, each new element inherits the common event process of the array.

By using the control array mechanism, each and every new control inherits the common event procedures previously written for the array. For illustration, if your form has some text boxes that each receives a date value, the control array can be put up so that all of the text boxes share similar validation code.

For illustration you can have some Text Boxes with similar name and differentiate them with the help of a subscript. We will observe how to create a control array. We are going to create an array of the textboxes. Follow the steps below to create a control array of textbox.

1. Build a VB project.

2. Click the command button and attach it on the form.

3. Drag the Text Box control and set it on the form.

4. Copy the Text Box control.

5. Paste the copied Text Box control on the form.

6. The following message would be exhibited.

7. You previously have a control named Text1'. Do you desire to create a control array?

8. Choose yes and the Text Box control would be pasted on the form.

9. Now Paste as many times as you wish for. For illustration to create a control array with 3 elements paste the control 2 times.

10. Handle the click event, for the command button.

11. Comprise the code below in the event handler.

Private Sub Command1_Click()

Dim an As Integer

For an = 0 To 2

Text1(an).Text = Val(Text1(an).Text) + 5

Next an

End Sub

The Val function changes the content of Text1 to numeric. The subscript, an, is used to access the different text boxes; an (0) would refer to the first text box, an (1) would refer to the second text box and an(2) would refer to the third text box. 

Posted Date: 10/10/2012 1:04:53 AM | Location : United States







Related Discussions:- Control array, Assignment Help, Ask Question on Control array, Get Answer, Expert's Help, Control array Discussions

Write discussion on Control array
Your posts are moderated
Related Questions
The Frame: As the name suggests, the frame is a combination of the building blocks, structure and the borders of an item. The frame gives the "physical" presence to a window.

CONTROL STATEMENTS   The conditional expression uses a comparison operator that results in true or false value. If the comparison is valid the outcome is true, or else the out

MODELESS DIALOG The Dialog boxes are either modal or modeless. The modal dialog box should be closed (Unloaded or hidden) before you can continue the working with the rest of t

APPWIZARD   The Appwizard is a tool used for creating a project. It follows a series of steps to create a project. Steps Involved in Creating A Project: Step 1: Fr

GDI OBJECTS   The CDC provides 5 versions for the GDI objects. They are fonts, brushes, pens, bitmaps and regions. The Select Object function substitutes the current GDI objec

FILES IN A VB PROJECT The project file has the.vbp extension. The form in which we draw has the .frm extension; .mod denotes the module file; .cls denotes the class file; .res

write a XML with database with book details( book id, author ,subject, published year, vendor,price, language )

What are the differences between Property Get, Set and Let? Set - Value assigned to ActiveX Object from the form. Let - Value retried to ActiveX Object from the form. Get- Assigns

I have an external application I open from visual studio (excel). I want to reposition where that opens (top, left).. How do I do that?

DOCUMENT VIEW ARCHITECTURE The Document/View architecture is used to build an application based on the Microsoft Foundation Classes library. The Document/View architecture is s