Time: 10:30 - 11:30. (There is a poor one hour in the morning.) ---------------- I have to get up early in the future. . Review the VB knowledge yesterday. To add a control in the control array during the program runtime, such as a button. At this time, you can use the LOAD statement, the syntax is as follows: Load Object (index) must ensure that there is at least one control in the control array (you can set the INDEX property of the control to 0). It should be noted that the VB only allows an array of controls to include 32767 controls (PS: the value range of the integer variable is -32768 ~ 32767). Private Sub CMDBTN_Click (index as integer) DIM BTN As CommanDbutton Dim IIndex as integer IIndex = cmdbtn.count if Iindex <= 32767 THEN --------------------- ------------------------------------------ LOAD CMDBTN (IINDEX)? ? ? ? ? ? ? ========================================== = = cmdbtn (IINDEX) - -------------------------------------------------- --------------- with btn .top = cmdbtn (IINDEX - 1) .top 620.caption = "Command" & IIndex 1 .visible = true end with ---- -------------------------------------------------- ------------ SET btn = Nothing? ? ? ? ? ? ? ? ? ? ? ? ? ? -------------------------------------------------- --------- Endness Sub ---- Run the program and click the button, the program adds a new button in the form. -------------------------------------------------- -------------- The so-called control array can simply understand the shared control group, type, and events, such as drawing 10 Text controls, their Name properties are TXTIndex. By using the control array, these Text controls can be shared with the same event process.
Its maximum benefit is: saving code, increasing readability, and also reduces memory overhead control arrays can be divided into static array and dynamic arrays, and there are still things in the whole afternoon, there should be a good plan: ===== ============================================================================================================================================================================================================= ======== SET statement returns
Assign object reference to variables or properties. Syntax SET ObjectVar = {[New] ObjectExpression | Nothing} The syntax for the SET statement contains the following sections:
Partially describes objectvar necessary. The name of the variable or attribute follows the standard variable naming convention. NEW is optional. Normally use New when declaring so you can implicate an object. If New is used with SET, a new instance of this class will be created. If the ObjectVar contains an object reference, release the reference when you assign a new value. You cannot use the new keyword to create a new instance of any internal data type, or you cannot create a slave object. ObjectExpression is required. Other variables of the object name, the same object type, or the expression of a function or method of the same object type. Nothing is optional. Disconnect ObjectVar association with any specified object. If there is no other variable to point to ObjectVar, all the systems and memory resources associated with this object are released to Nothing. Note To ensure legal, Objectvar must be an object type that is consistent with the assigned object. DIM, Private, Public, Redim, and Static statements have only declare the variables of reference objects. This variable does not reference any actual object before use the SET statement to a specific object. The following example illustrates how to use DIM to declare an array of Form1 types. The Form1 actually has no instance. Then use SET to assign a reference to the newly created form1 to myChildForms variables. These codes can be used to create a child form in the MDI application. DIM MyChildForms (1 to 4) as Form1
Set mychildForms (1) = new form1
Set mychildforms (2) = new form1
Set mychildForms (3) = new form1
SET myChildForms (4) = New Form1
Typically, when using SET to assign an object to a variable, a copy of the object is not created for the variable, but a reference to the object is created. There are multiple object variables to reference the same object. Because these variables are only references to the object, not the object's copy, so any changes to the object will react to all variables that reference the object. However, if you use the New key in the Set statement, you will actually create an instance of this object.