[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

Restarting a form in VB6

I am trying to unload my form and start over.  Why doesn't the following code work?  It simply ends the program


Splash4.Show
            
            Unload CAPOrganizing
            
            Load CAPOrganizing
            
            Splash4.Hide

Open in new window

0
al4629740
Asked:
al4629740
  • 4
  • 2
  • 2
  • +2
4 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
if Splash4 is your loading/first form, ending it also ends the program
0
 
al4629740Author Commented:
I don't understand what your saying exactly.  Can you explain that again?
0
 
Éric MoreauSenior .Net ConsultantCommented:
what is your starting form? which one is set in the project properties?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
eemitCommented:
You also need:
CAPOrganizing.Show
0
 
al4629740Author Commented:
my first form is a splash screen also called Splash1

Would it be instead

            Splash4.Show
           
            Unload CAPOrganizing
           
            CapOrganizing.Show
           
            Splash4.Hide
0
 
Martin LissRetired ProgrammerCommented:
Why do you want to start over and what exactly do you mean by "start over". End the program and restart it, or something else?
0
 
al4629740Author Commented:
I would like to basically unload and load the form again....
0
 
ArkCommented:
Would it be instead
            Splash4.Show
            Unload CAPOrganizing
            CapOrganizing.Show
            Splash4.Hide
Exactly. The only addidion may be

CAPOrganizing.Hide 'In case unloading takes a wile - hide form if it's visible and show splash
Splash4.Show
Unload CAPOrganizing 'etc
But in most cases youdon't need reload form. If you have some code in Form_Load event - place it in some Public Sub, smth like this:
Private Sub Form_Load()
   InitForm
End Sub
Public Sub InitForm(probably_some_initial_value As Something)
   'Your initializing/updating/refreshing code here
End Sub

Open in new window

And instead of reloading form just call
CAPOrganizing.InitForm(conditions)
0
 
al4629740Author Commented:
How does initform work?

What do I put for conditions?
0
 
ArkCommented:
Why do you need to reload form? In most cases you just need to execute code in Form_Load event. So you can move all this code into InitForm sub:
Was:
Private Sub Form_Load()
  'A lot of initializing code here
End Sub

Open in new window

Should be:
Private Sub Form_Load()
  Call InitForm(0) '0 means you call InitForm for the first time, from withing Form_Load Event 
End Sub
Public Sub InitForm(condition As Long)
  'A lot of initializing code here
End Sub
'Any time you need 'Reload' form
Call YourFormName.InitForm(1) 

Open in new window

Condition parameter is optional, just in case you need to tell InitForm Sub to execute or not some staff according to your needs, for example, during first call (condition=0) populate listbox/ComboBox with values and set .ListIndex=0, while for other calls leave populated controls as they are and set .ListIndex = some other value.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now