----------------------------窗体1------------------------- Private Sub Form_Load() List1.AddItem "窗体1" List1.AddItem "窗体2" List1.AddItem "窗体3"End SubPrivate Sub List1_DblClick() Dim stran As Form Set stran = New Form2 If a(List1.ListIndex) = 0 Then a(List1.ListIndex) = List1.ListIndex + 1 stran.Caption = List1.List(List1.ListIndex) stran.Show End If End Sub ----------------------------窗体2--------------------------------- Private Sub Form_Unload(Cancel As Integer) Dim inte As Integer inte = Form1.List1.ListIndex a(Val(inte)) = 0 End Sub ------------------------模块------------------------------------ Public number As Integer Public a(255) As Integer
----------------------------窗体2--------------------------------- Private Sub Form_Unload(Cancel As Integer) Dim inte As Integer inte = Form1.List1.ListIndex a(Val(inte)) = 0 End Sub ----------------------------修改为------------------ Dim inte As Integer Private Sub Form_Load() inte = Form1.List1.ListIndexEnd SubPrivate Sub Form_Unload(Cancel As Integer) a(Val(inte)) = 0 End Sub
singleton 对象创建型模式1.保证一个类仅有一个实例,并提供一个访问他的全局访问点
对于一个类来说,只有一个实例是很重要的,虽然系统中可以有许多打印机,但却只应该有一个打印机假脱机(printer spooler)
怎样保证一个类只有一个实例并且这个实例易于被访问,一个更好的办法是:让类自身负责保存它的唯一实例
Private Sub Form_Load()
List1.AddItem "窗体1"
List1.AddItem "窗体2"
List1.AddItem "窗体3"End SubPrivate Sub List1_DblClick()
Dim stran As Form
Set stran = New Form2
If a(List1.ListIndex) = 0 Then
a(List1.ListIndex) = List1.ListIndex + 1
stran.Caption = List1.List(List1.ListIndex)
stran.Show
End If
End Sub
----------------------------窗体2---------------------------------
Private Sub Form_Unload(Cancel As Integer)
Dim inte As Integer
inte = Form1.List1.ListIndex
a(Val(inte)) = 0
End Sub
------------------------模块------------------------------------
Public number As Integer
Public a(255) As Integer
Private Sub Form_Unload(Cancel As Integer)
Dim inte As Integer
inte = Form1.List1.ListIndex
a(Val(inte)) = 0
End Sub
----------------------------修改为------------------
Dim inte As Integer
Private Sub Form_Load()
inte = Form1.List1.ListIndexEnd SubPrivate Sub Form_Unload(Cancel As Integer)
a(Val(inte)) = 0
End Sub