Results 1 to 13 of 13

Thread: Where do I put "Sub Main" ?? (Resolved)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    47

    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.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    47

    ...

    I'm getting the following error:

    "No accessible 'Main' with the appropriate signature found in myProjectName.frmSelect"

    What can I do here??

    Thanks.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Verify you have the general setting set as in the attached image .
    Attached Images Attached Images  

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    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.

  7. #7
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    why would you waste your time doing that?
    VB Code:
    1. Public Sub Main()
    2.     Dim frmMain As New fclsMain
    3.     Application.Run(frmMain)
    4. 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

  8. #8
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    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.

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  11. #11
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    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?

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    EnableVisualStyles() property is only in VS.NET 2003 .

  13. #13
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    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
  •  



Click Here to Expand Forum to Full Width