Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » General Visual Basic » Restart form


Restart formExpand / Collapse
Author
Message
Posted 6/6/2008 9:23:48 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/7/2008 1:21:12 AM
Posts: 2, Visits: 2
Is there a way I can restart a form like it has been exited and started again? Otherwise I would have to reset every counter, sprite, timer and everything manually.
Post #25134
Posted 6/6/2008 12:03:27 PM
Forum God

Forum God

Group: Moderators
Last Login: 2 days ago @ 1:42:32 PM
Posts: 1,073, Visits: 9,408
I'm not sure this is the best way of doing it but it should work. It will take 2 forms. For this sample on Form one place a command button and use this code.
Option Explicit
Dim strText As String

Private Sub Command1_Click()
Dim frm As Form

    strText = "Testing"
    
    'The load event of form 2 will reload form1'
    Form2.Hide
    
    'check if form2 is loaded and unload if it is
    For Each frm In Forms
        If frm.Name = "Form2" Then
            Unload frm
            Set frm = Nothing
        End If
    Next frm

End Sub

Private Sub Form_Load()
    Me.Caption = strText
End Sub

And here is the code for Form2

Option Explicit

Private Sub Form_Load()
    Unload Form1
    'To test comment this line and check the caption on form 1
    Set Form1 = Nothing
    Form1.Show
End Sub
Post #25135
Posted 6/7/2008 1:26:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/7/2008 1:21:12 AM
Posts: 2, Visits: 2
Ok thanks
Post #25136
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 3:41am