Visual Basic 6 :: Unload Dynamically Created Form

2019-07-26 22:43发布

I'm trying hard to solve that issue without any luck :(

Here is my code :

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private frm As Form

Public Sub GenerateForm()

    Set frm = New myForm

    With frm
        .Width = 4000
        .Height = 3000
        .Caption = "Message"
    End With

    frm.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2

    frm.Show vbModal

    Sleep 3000

    Unload Me
    Set frm = Nothing

End Sub

Private Sub Command1_Click()

    GenerateForm

End Sub

I want to close the newly created form automatically after 3 seconds.

2条回答
放我归山
2楼-- · 2019-07-26 23:20

You could use the timer like this, once it reaches 3 seconds (3000) it will close the form and open another one.

Private Sub Timer1_Timer()
    If Timer1.Interval = 3000 Then
        frm_Menu.Show
        Unload frmSplash
        Timer1.Enabled = False
    End If
End Sub
查看更多
不美不萌又怎样
3楼-- · 2019-07-26 23:39

Windows opened in modal mode wait for user input, so the statements after

frm.Show vbModal

will not execute.

.

You have two solutions:

a) remove vbModal

b) add Timer on myForm and set Interval to 1000 (mean 1 second), next add this code in Timer event:

Private Sub Timer1_Timer()
    Static sec As Integer
    sec = sec + 1
    If sec >= 3 Then
        Timer1.Enabled = False
        Unload Me
    End If
End Sub

Last, you should use

Unload frm

since Unload Me is wrong.

查看更多
登录 后发表回答