Control array, Visual Basic Programming

Assignment Help:

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. 


Related Discussions:- Control array

Steps to create a rectangle in the client region, STEPS TO CREATE A RECTANG...

STEPS TO CREATE A RECTANGLE IN THE CLIENT REGION 1. Generate a SDI application and name it as a brush. 2. Handle the WM_LBUTTONDOWN message for the CBrushView object id.

Appwizard, APPWIZARD   The Appwizard is a tool used for creating a p...

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

Creation of the menu in visual basic, Creation of the Menu in VB 1. Ini...

Creation of the Menu in VB 1. Initiate a new project by choosing a file and then new project. 2. Now select the Standard EXE as the Project type. 3. Build the Form1 activ

Declaring variables in vbscript, You declare variables explicitly in script...

You declare variables explicitly in script via the Dim statement, the Public statement, & the Private statement. For illustration: Dim DegreesFahrenheit You declare multiple

Vbscript operators, VBScript Operators VBScript contain a full range of...

VBScript Operators VBScript contain a full range of operators, including comparison operators, arithmetic operators, concatenation operators, and logical operators.

Program for computing automobile repair bills, A program is needed to assis...

A program is needed to assist computing automobile repair bills. The cost of labor is $35 per hour. The costs for parts are subject to a 5% sales tax, which should be added t

Source property, Returns or sets the name of the object or application whic...

Returns or sets the name of the object or application which generated the error originally. The Source property indicates a string expression which is usually the class name or pro

Help file property, Sets or returns wholly qualified path to a Help File. I...

Sets or returns wholly qualified path to a Help File. If Help file is indicated in HelpFile, it is called automatically when the user clicks Help button (or presses the F1 key) in

Mdi application - types of project using visual c++, MDI Application: ...

MDI Application: The MDI application utilizes the main frame window as the work space in which the user can open more document frame windows.

Variable scope, Variables must always be described with the smallest scope ...

Variables must always be described with the smallest scope possible. VBScript variables can have the given scope. Scope Where Variable is Declared

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd