Start sequence

D

Doug Bell

Hi,
I am trying to learn VB.Net by following some examples.
I am not sure I am following the order of events but could someone confirm:
Project "ScheduleFileTfr" has property "Startup Object:" set to "FormMain"
FormMain has code:
Public Shared Sub Main()

Dim initForm As New MainForm

Application.Run()

End Sub

initForm declares an instance of the Class MainForm

What does Application.Run() do?

Next Procedure to run is "Public Sub New()"

I assume this runs because the "MainForm" is set as a startup parameter of
the project.

It doesn't run if it isn't declared.

Then the procedure Public Sub New runs:

Public Sub New()

MyBase.New()



'This call is required by the Win Form Designer.

InitializeComponent()

'This form isn't used directly so hide it immediately.

Me.Hide()

'Retrieve settings from the registry.

dacGetRegSettings()

'Setup the tray icon.

InitializeNotifyIcon()

End Sub

InitializeComponent() calls procedure to set default parameters of the form

Me.Hide hides the form. What is the difference between hiding the form and
setting its property Visible = False ?

dacGetRegSettings() is a procedure in a module that I wrote to retrieve some
registry keys and save them as public variables

InitializeNotifyIcon() is a (sample) procedure that initialised an icon and
menu in the Systray.

Is this why the Application.Run is required?

When I tried to add some code to check for a second instance of the process
running, I could detect it but Application.Exit wouldn't (self) terminate
the application.

I can certainly see the power of VB.Net but I am really struggling to get on
top of it any recomendations for good books? I have not had much to do with
OOP before.



Thanks



Doug
 
H

Herfried K. Wagner [MVP]

* "Doug Bell said:
I am trying to learn VB.Net by following some examples.
I am not sure I am following the order of events but could someone confirm:
Project "ScheduleFileTfr" has property "Startup Object:" set to "FormMain"
FormMain has code:
Public Shared Sub Main()

Dim initForm As New MainForm

Application.Run()

End Sub

initForm declares an instance of the Class MainForm

What does Application.Run() do?

Replace 'Application.Run()' with 'Application.Run(InitForm)' and select
'Sub Main' as startup object in the project properties.
Next Procedure to run is "Public Sub New()"

I assume this runs because the "MainForm" is set as a startup parameter of
the project.

That's because 'Dim InitForm As New MainForm()' calls the form's
constructor ('Sub New').
InitializeComponent() calls procedure to set default parameters of the form

It adds the controls/components to the form.
Me.Hide hides the form. What is the difference between hiding the form and
setting its property Visible = False ?

It's the same. Pressing the F1 key on the 'Hide' method would give you
the same answer.
dacGetRegSettings() is a procedure in a module that I wrote to retrieve some
registry keys and save them as public variables

InitializeNotifyIcon() is a (sample) procedure that initialised an icon and
menu in the Systray.

Is this why the Application.Run is required?

No. 'Application.Run' is required to construct the program's message loop.
When I tried to add some code to check for a second instance of the process
running, I could detect it but Application.Exit wouldn't (self) terminate
the application.

Simply close the main form by calling its 'Close' method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top