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