| Load Statement |
Syntax
Load object
object
Use: Required
Data Type: A Form or Control object
An expression that evaluates to a form or control.
Description
Loads a form or control into memory.
Rules at a Glance
When a control or form is first loaded using the Load statement, it's resident in memory, but it isn't visible on the screen. To make a form visible, use the form's Show method. To make a control visible, set its Visible property to True.
Sidebar 5. Creating a Dynamic Control ArrayTo create a dynamic control array—that is, an array of controls you can add to at runtime—you must first place a control of the required type on the form and set its index property to 0. You can then use the Load statement to create new controls based on the control whose Index is 0. The new controls inherit all the properties of the original control, including its size and position. This means you must set the Left and Top properties for the new controls; otherwise, all your controls will sit on top of each other! These newly loaded controls are also hidden, so you must also set their Visible property to True once you have sized and positioned them. The following example creates a control array containing five command buttons that appear horizontally across a form: Private Sub Form_Load() Dim intCtrlCtr As Integer Dim varCtrl As Variant For intCtrlCtr = 1 To 4 Load cmdArray(intCtrlCtr) cmdArray(intCtrlCtr).Caption = "Button #" _ & intCtrlCtr + 1 cmdArray(intCtrlCtr).Top = cmdArray(0).Top cmdArray(intCtrlCtr).Left ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access