Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

form as control array

Can a form be a control array?  I have tried using MyForm.Control(X).Show, but it doesn't seem to work.  And how does control collection work?
0
JaneKim
Asked:
JaneKim
  • 2
1 Solution
 
watyCommented:
When the form is shown, all the visible controls belonging to this form are shown. MyForm.Control(X).Show is invalid.
MyForm.show is valid.

If you want to do dynamically some form, do as follow :
     Dim frm as New Form

     frm.Show


The control collection works as other collections :

Samples :
Me.Controls.Count
Me.Controls(1).Caption = "&Caption"


0
 
watyCommented:
Here is another sample :

Sub TraductForm(TheForm As Form)
   On Error GoTo ERROR_TraductForm
   
   Dim nI   As Integer
   
   TheForm.Caption = Traduction(CStr(TheForm.Caption))
   
   For nI = 0 To TheForm.Controls.Count - 1
   
      If TypeOf TheForm.Controls(nI) Is Label Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is Menu Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is CommandButton Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is Frame Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is CheckBox Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is OptionButton Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      End If
   Next
   
   Exit Sub
   
ERROR_TraductForm:
   Exit Sub
   
End Sub

0
 
wfordCommented:
you could do this too:
Dim FormX as Form

For Each FormX In Forms
    If Not FormX.Name = Me.Name Then FormX.show
Next

a form is a special type of control, it is a control, however you cannot make it an array, at least not as far as i know!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now