Main subroutine? Common?

S

StrandElectric

Hi. I have a form where I want to display information *before* pressing
any command button. In vb6 I believe I used something like Sub main. What is
the syntax in vb.net?
 
O

Onur Güzel

 Hi.  I have a form where I want to display information *before* pressing
any command button. In vb6 I believe I used something like Sub main. Whatis
the syntax in vb.net?

It's not clear. If you're dealing with Sub Main, then it's likely a
console application whereas you talk about a form and a command button
which are involved in a Winform app.

Guessing wild as you may have intended to state a winform app, check
form_load event which is fired before the form and other controls
loaded visually. If you want to do something prior to initialization
of controls, call your custom sub or code block before
InitializeComponent() method.

For console apps, you're free to declare or put your custom subs and
variables globally inside a given "module". Then the application calls
"sub main" (which is entry point) to execute actual program code.

HTH,

Onur
 
S

StrandElectric

Hi. I have a form where I want to display information *before* pressing
any command button. In vb6 I believe I used something like Sub main. What
is
the syntax in vb.net?

It's not clear. If you're dealing with Sub Main, then it's likely a
console application whereas you talk about a form and a command button
which are involved in a Winform app.

Guessing wild as you may have intended to state a winform app, check
form_load event which is fired before the form and other controls
loaded visually. If you want to do something prior to initialization
of controls, call your custom sub or code block before
InitializeComponent() method.

For console apps, you're free to declare or put your custom subs and
variables globally inside a given "module". Then the application calls
"sub main" (which is entry point) to execute actual program code.

HTH,

Onur

Thanks Onur. I'll make it a bit clearer (I hope!). I am creating a windows
form app. When it loads I want to start it up with some variables displayed
on the page before we start pressing any buttons. In vb6 I sude to do this
in Sub Main. In vb.net what exactly and where should be put to start the
form off immediately?
 
O

Onur Güzel

It's not clear. If you're dealing with Sub Main, then it's likely a
console application whereas you talk about a form and a command button
which are involved in a Winform app.

Guessing wild as you may have intended to state a winform app, check
form_load event which is fired before the form and other controls
loaded visually. If you want to do something prior to initialization
of controls, call your custom sub or code block before
InitializeComponent() method.

For console apps, you're free to declare or put your custom subs and
variables globally inside a given "module". Then the application calls
"sub main" (which is entry point) to execute actual program code.

HTH,

Onur

Thanks Onur. I'll make it a bit clearer (I hope!). I am creating a windows
form app. When it loads I want to start it up with some variables displayed
on the page before we start pressing any buttons. In vb6 I sude to do this
in Sub Main. In vb.net what exactly and where should be put to start the
form off immediately?

Well, i would choose one of two.

First, as typical you can set all the variables before the form loaded
in form_load event like this:

Public Class Form1
Dim varToDisplay As String = "foo"
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' do something with varToDisplay
' here before the form is shown
End Sub
End Class

Second, you can choose the new model of VB since .NET 2.0 (VB 2005)
which is My.Application.Startup event that runs when the application
runs (before the form is loaded). You should go to Project properties
by right clicking project name in solution explorer -> Properties ->
Application tab -> View application events (at the bottom). Then
handle the startup event and code:

Partial Friend Class MyApplication
' Usage
Public Sub Me_Startup( _
ByVal sender As Object, _
ByVal e As _
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs _
) Handles Me.Startup

' Do something here on startup

End Sub

For remarks and more info:
http://msdn.microsoft.com/en-us/library/t4zch4d2(v=VS.80).aspx

HTH,

Onur


End Class
 
C

Cor

Strand,

Double Clicking on your form template then the sub with its handler
mybase.load appears that is the most commonly used in VB.Net (and currently
also more and more C#) for initializing.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End sub

There are at least eleven other methods for this.

Success

Cor

"StrandElectric" wrote in message
Hi. I have a form where I want to display information *before* pressing
any command button. In vb6 I believe I used something like Sub main. What is
the syntax in vb.net?
 

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

Top