创建类实例时为什么要用Collection集合???
<p>有这样一段代码:</p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span lang="EN-US" style="mso-bidi-font-size: 10.5pt;">‘类模块Cmds的代码</span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="FONT-FAMILY: SimSun; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';">Option Explicit <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">Public WithEvents cmd As CommandButton <p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">Private Sub cmd_Click() <p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> UserForm1.TextBox1 = cmd.Caption <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">End Sub </p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><p></p> </p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">‘窗体UserForm1的代码<p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">Option Explicit <p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><font color="#f70909">Dim co As New Collection</font>
<p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">Private Sub UserForm_Initialize() <p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> Dim i% <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> Dim myc As Cmds <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> For i = 1 To 5 <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> Set myc = New Cmds <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> Set myc.cmd = Me.Controls("CommandButton" & i) <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><font color="#ff3300"><span style="mso-spacerun: yes;"> co.Add myc</font>
<p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> Next i <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><span style="mso-spacerun: yes;"> Set myc = Nothing <p></p></span></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;">End Sub </p><p>请问:红色的两段代码有什么意义?为什么去掉了就不行?</p><p>
<p></p></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"></p><p class="MsoNormal" align="left" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"></p><p class="MsoNormal" style="BACKGROUND: #fafdf9; MARGIN: 0cm 69.95pt 0pt 21.65pt; TEXT-INDENT: -0.65pt; mso-para-margin-top: 0cm; mso-para-margin-right: 6.66gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.0gd; mso-char-indent-count: -.06;"><p></p></p> 本帖最后由 作者 于 2007-12-20 15:13:20 编辑 <br /><br /> <p>myc的生存期在UserForm_Initialize后就完结了,无法触发cmd_Click事件</p><p>set myc=nothing释放内存</p> 类模块定义问题。
页:
[1]