Sub Main()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Please bear with me as this is a very basic question.

Using Sub Main() within a console application gets executed when the console
application first starts. Does the same hold true for a windows application
created in VB.net?

I've tried a simple message box display and I keep getting build errors.

Sub Main()
MsgBox("Test Question?", vbInformation, "Title")
End Sub

The build error I am getting is as follows:

No accessible 'Main' method with an appropriate signature was found in
'WindowsApplication3.Form1'.


thanks in advance,

devin
 
Devin,, go to your project properties - Under the Common Properties/General
select Sub Main from the Startup object dropdown. Recompile.

HTH,
Joe Johnston
www.gotboxer.com
 
You have to select "Sub main" as the startup funtion in the properties of
the form window I think...
 
Devin,, go to your project properties - Under the Common Properties/General
select Sub Main from the Startup object dropdown. Recompile.

Joe,

That worked perfectly now the only problem I am having is that once I
display my alert dialog box the application quits and my form with a TextBox
is not displayed.

Here's the code I am using:


Public Module StartUpTest
Sub Main()
MsgBox("Test Question?", vbInformation, "Title")
End Sub
End Module

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(48, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(192, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
End Class

Sorry for such a basic question but I'm trying to learn VB.net after 10
years of lingo programming in Macromedia Director.

Thanks in advance,

devin
 
Try some code like this in your sub main :

Public Module StartUpTest
Sub Main()
MsgBox("Test Question?", vbInformation, "Title")
Dim frmMain New Form1
Application.Run(frmMain)
End Sub
End Module

HTH,
Joe Johnston
www.gotboxer.com
 
Try some code like this in your sub main :

Public Module StartUpTest
Sub Main()
MsgBox("Test Question?", vbInformation, "Title")
Dim frmMain New Form1
Application.Run(frmMain)
End Sub
End Module

Joe,

I added the additional lines of code and I am getting two errors:

End of statement expected.
Name 'frmMain' is not declared.

Does the frmMain need to be declared as an object?

thanks in advance,

devin
 
DOH!! Add the 'AS' in Dim frmMain as New Form1

Public Module StartUpTest
Sub Main()
MsgBox("Test Question?", vbInformation, "Title")
Dim frmMain as New Form1
Application.Run(frmMain)
End Sub
End Module

Sorry,
 
Public Module StartUpTest
Sub Main()
MsgBox("Test Question?", vbInformation, "Title")
Dim frmMain as New Form1
Application.Run(frmMain)
End Sub
End Module

Joe,

As Monty Burns would say "Excellent". Thanks for your help. I very much
appreciate it :)

take care and have a great day!

cheers,

devin
 
Back
Top