Search In Site

24 June, 2013

Arrey of forms in Visual Basic


Arrays Of Forms
The user wants to open 20 documents at the same time how can you keep track of all that? Would not it be nice if you could use arrays of forms in Visual Basic and just refer to each form with one single array index?
You can do that in Visual Basic (in fact, you can create arrays of many types of objects,
excluding such objects that there can only be one of, like the application object, App). You
create an array of forms just as you would create an array of any other kind of object; here,
we re creating an array of Form1 objects, because that s the type of form we ll use as MDI
children in an MDI program:
Dim Forms(1 To 20) As Form1
If we declare this array, Forms(), as a form-level array in the MDI form, we can refer to that
array in all procedures in the MDI form. For example, we might want to create and display a
new MDI child form in a procedure named NewWindow_Click():
Private Sub NewWindow_Click()
End Sub
Next, we set up a static variable to hold the total number of MDI child forms,
NumberForms, and increment that variable now that we re adding a new form:
Private Sub NewWindow_Click()
Static NumberForms
NumberForms = NumberForms + 1
...
End Sub
Now, we create a new form and add it to the form array:
Private Sub NewWindow_Click()
Static NumberForms
NumberForms = NumberForms + 1
Set Forms(NumberForms) = New Form1
...
End Sub

Throughout the rest of the program, now, we re able to refer to the new form as a member of
the form array; here, for example, we set its caption and show it, referring to it with an index
value in the form array:
Private Sub NewWindow_Click()
Static NumberForms
NumberForms = NumberForms + 1
Set Forms(NumberForms) = New Form1
Forms(NumberForms).Caption = "Document" & Str(NumberForms)
Forms(NumberForms).Show
End Sub

0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget