如何打开form1的同时 ,让form2执行form2里的初始化
请教大家一个问题:
就是打开form1的同时 ,让form2执行它的初始化,即:
执行form2里的Private Sub Form_Load()里的东西,此时form2窗口不显示,因为我单独在form1里做了个command1来form2.show ,这样form2打开后就不用再执行初始化了 。
我这样做的目的是先在form1里玩会游戏,这个时间来让form2初始化。
下面是form2初始化的内容:
Private Sub Form_Load()
Dim str1 As String
Dim arrOutput(1) As Byte
arrOutput(0) = &H1
arrOutput(1) = &H30
MSComm1.Output = arrOutput
DoEvents
Call Sleep(1000)
str1 = "DP140" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(1000)
str1 = "DI180" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(1000)
str1 = "DD120" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(1000)
str1 = "SV14564" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(1000)
str1 = "SA60000" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(1000)
str1 = "FE0" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(10000)
str1 = "MR436907" & Chr(13)
Me.MSComm1.Output = str1
DoEvents
Call Sleep(10000)
str1 = "DH" & Chr(13)
Me.MSComm1.Output = str1
End Sub
[解决办法]
建议楼主还是用 Timer 控件来解决算了,发觉用 Sleep() 总会把整个进程‘卡死’的。
'Form1 Code:Option ExplicitPrivate Sub Command1_Click() Unload Form2 EndEnd SubPrivate Sub Form_Load() Me.Show Load Form2' Form2.Timer1.Interval = 10' Form2.Timer1.Enabled = TrueEnd Sub
[解决办法]