You are here:

Visual Basic/VB 6.0 Command Buttons

Advertisement


Question
I would like one of my command buttons to take the viewer back to the starting slide of the program and I also would like to incorporate an exit button into the last program slide so that the user can exit the VB application totally.
-------------------------

Followup To

Question -
How do I program a command button in VB 6.0 to 1) exit/close that program application and return back to the beginning Microsoft windows page

and

2) return the viewer back to the initial starting slide?

Is there specific programming language I need to code the buttons with and if there is, can you tell me what that language is?

Answer -
Pls. specify clearly what really you are doing !
What is meant by starting slide.


Ravish


Answer
Hi Diana,
You Would Have To Do A Little Hard Work To Achieve That:

First Of All Add A Module To Your Program and copy the following code there !!!

'***************************************
'***************************************
Public gForms() As Form
Public Sub LoadForm(F As Object)
   Dim I As Integer
   I = UBound(gForms)
   Set gForms(I) = F
   ReDim Preserve gForms(1 To I + 1)
   
End Sub

Public Sub unloadall()
   Dim I As Integer
   For I = LBound(gForms) To UBound(gForms) - 1
       Unload gForms(I)
   Next I
   For I = LBound(gForms) To UBound(gForms) - 1
       Set gForms(I) = Nothing
   Next I
   ReDim gForms(1 To 1)
   Form1.Show
End Sub

'*******************
'*******************




Now paste following code on the Form_Load Event of the starting form (Assume  Form1 as starting slide or form)

'*******************
'*******************

Private Sub Form_Load()
       ReDim gForms(1 To 1)
End Sub

'*******************
'*******************


Now paste the following code on all the other form's Form_Load events:

'*******************
'*******************
Private Sub Form_Load()
       Call LoadForm(Me)
End Sub
'*******************
'*******************


Now As You Have Said, You Are Having A Button on Each Form, clicking on  Which Closes All The Open Forms Except the Strting form. Let Us assume that, there name is Command1.

Paste The Following Code On The Click Event Of That Button !!
'*******************
'*******************
Private Sub Command1_Click()
   Call unloadall
End Sub
'*******************
'*******************


Finally, You Have Said That, There is a button on the starting form, clicking on Which Closes All The Other And The Main Form And Closes The Application. Assume That Button Is cmdCloseApp.

Paste The Following Code To Click Event Of This Button :

'*******************
'*******************
Private Sub cmdCloseApp_Click()
   Call unloadall
   Unload Me
   End  
End Sub


That's All. Things Would Work As You Expected !!

Bye !!

Please Revert Whether It Worked Or Not !!!  

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ravish Kumar

Expertise

Basics, GUI Objects, Database programming, reports generation, chart and graphics, CO

Experience

4 years of Software Development industry experience

Organizations
Infotech Enterprises Ltd, Hyderabad NIT, Patna ABC Online, Patna

Education/Credentials
B.Tech. Electronics & Telecomm. B.Sc. Maths Honors

©2014 About.com. All rights reserved.