|
-
Dec 29th, 2003, 09:36 AM
#1
Thread Starter
Member
Where do I put "Sub Main" ?? (Resolved)
I've got an application that won't build because "Sub Main" is not found. I'm used to Java where a Main method is placed right into a class. This doesn't seem to work with VB.NET though.
Where should the "Sub Main" be placed in my application? The application consists of a Windows Form class with a bunch of click events.
Thanks!! =)
Last edited by cpluspluser; Dec 29th, 2003 at 11:21 AM.
-
Dec 29th, 2003, 09:55 AM
#2
Frenzied Member
check and make sure the Sub Main is not set as the startup object.
Project>ProjectName Properties then verify the startup object.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Dec 29th, 2003, 10:22 AM
#3
Thread Starter
Member
...
I'm getting the following error:
"No accessible 'Main' with the appropriate signature found in myProjectName.frmSelect"
What can I do here??
Thanks.
-
Dec 29th, 2003, 10:27 AM
#4
Sleep mode
If your application starts from a module or a class then you need a Main sub , otherwise , set your application startup object (as Memnoch1207 stated) as the form you want to show first .
-
Dec 29th, 2003, 10:31 AM
#5
-
Dec 30th, 2003, 06:02 PM
#6
PowerPoster
Sub Main
Hi cpluspluser,
On looking at the various responses I cannot see that anyone answered your question.
If you start a VB.Net application from a form the application will stop when you close that form. It is best to start with a Sub Main procedure which must be placed in a module. The sub Main should read something like:
Public Sub Main()
Dim frmMain As New fclsMain
Application.Run(frmMain)
End Sub
You then make the Sub Main the start up object in the Project Properties dialog window.
Regards,
Taxes.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 30th, 2003, 06:28 PM
#7
Frenzied Member
why would you waste your time doing that?
VB Code:
Public Sub Main()
Dim frmMain As New fclsMain
Application.Run(frmMain)
End Sub
When you can just set the frmMain form as the start up object in the project properties?
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Dec 30th, 2003, 07:35 PM
#8
Hyperactive Member
and to add my own tuppenceworth:
okay, the startup is a project property and can either be a form in your project or you can add a module with a sub main as others have indicated.
Either works, however if like me you are using VS2003 and want to take advantage of say something like Application.EnableVisualStyles(), or have other code you want to execute before showing the first form
then you will you use a main module.
However you can always go to the project properties and either select sub main as your startup on any form in your project.
-
Dec 30th, 2003, 10:28 PM
#9
Sleep mode
Originally posted by taxes
Hi cpluspluser,
On looking at the various responses I cannot see that anyone answered your question.
If you start a VB.Net application from a form the application will stop when you close that form. It is best to start with a Sub Main procedure which must be placed in a module. The sub Main should read something like:
Public Sub Main()
Dim frmMain As New fclsMain
Application.Run(frmMain)
End Sub
You then make the Sub Main the start up object in the Project Properties dialog window.
Regards,
Taxes.
First , we give hints on this forum and btw you should've quoted me .
-
Dec 31st, 2003, 04:38 AM
#10
PowerPoster
Hi All,
Ref. Richard Atherton's response.
I tried using a Sub Main in a form but received a build error "No accessible Main ..........". However, the application then proceded to run correctly!!!
In any case, why use Sub Main when you are going to start with a form anyway? Closing the startup form will still close the project.
Ref. Memnoch1207
"why would you waste your time doing that?"
For the reason I stated; that you avoid closing the project when the startup form is closed. Also see Richard Atherton's response.
Ref. Pirate
"First , we give hints on this forum and btw you should've quoted me ."
Sorry. I do not understand your comments. Please explain.
Regards,
Taxes.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 31st, 2003, 07:10 AM
#11
Frenzied Member
Originally posted by RichardAtherton
and to add my own tuppenceworth:
okay, the startup is a project property and can either be a form in your project or you can add a module with a sub main as others have indicated.
Either works, however if like me you are using VS2003 and want to take advantage of say something like Application.EnableVisualStyles(), or have other code you want to execute before showing the first form
then you will you use a main module.
However you can always go to the project properties and either select sub main as your startup on any form in your project.
what is this procedure for? Is this ONLY available in the 2003 release of VB?
-
Dec 31st, 2003, 07:18 AM
#12
Sleep mode
EnableVisualStyles() property is only in VS.NET 2003 .
-
Dec 31st, 2003, 10:43 AM
#13
Hyperactive Member
ah just to clarify, sub main should be conatained in a module not a form.
I tend to create a module with the same name as my project and add the sub main procedure there.
as an example here is our own sub main
Module ProLet21
Sub Main()
Application.EnableVisualStyles() 'VS2003 adopts buttion stle as per OOPeraing system
Application.DoEvents() ' MS bug required to make toolbar buttons visible in XP
Dim f1 As New Hub ' The first form to be shown
Application.Run(f1) ' simply run the app and show this form
Application.Exit() ' cleanly exit the application
End Sub
End Module
Then from the VS Menu: project: properties and select sub main as your startup
thats it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|