Results 1 to 8 of 8

Thread: [RESOLVED] Question about Sub Main()

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Resolved [RESOLVED] Question about Sub Main()

    I have an application that I am writing and i was initially using a form as the startup, but I want to use sub Main() as the start. This is the sub
    VB Code:
    1. Sub main()
    2.         Application.EnableVisualStyles()
    3.         Application.DoEvents()
    4.  
    5.         'Check to see if an installer is flagged for deletion
    6.         Dim inFile As String = My.Settings.KillInstaller
    7.         'if updates are enabled then do a check
    8.         If My.Settings.enableUpdates = True Then
    9.             'if flagged, delete the recent installer
    10.             If inFile <> String.Empty Then
    11.                 'check to see if installer exists in the temp directory
    12.                 If IO.File.Exists(My.Computer.FileSystem.SpecialDirectories.Temp & "\" & inFile) Then
    13.                     'Delete the previous installer
    14.                     IO.File.Delete(My.Computer.FileSystem.SpecialDirectories.Temp & "\" & inFile)
    15.                     'Update my.settings flag
    16.                     My.Settings.KillInstaller = String.Empty
    17.                 End If
    18.             End If
    19.             'Check for any new updates and run the update form if any exist
    20.             If checkUpdates() Then Exit Sub
    21.         End If
    22.         'Run the login screen
    23.         Application.Run(New Login)
    24.         Application.Exit()
    25.     End Sub

    It does a few things that are irrelevant to my question, which is this. I have enableVisualStyles in the sub, however when the application is run from this method, as opposed to haveing a form as startup item, all the linkLabels in my application look horrible, almost like it is changing the font. Has anyone else seen anything like this or perhaps see any errors in my code?

    Thanks
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Question about Sub Main()

    I can tell you are using 2005 from your use of the My keyword.

    So if you are using a Sub Main to start, that means you have disabled the application framework correct?

  3. #3

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Question about Sub Main()

    That is correct
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Question about Sub Main()

    well is there a specific reason you need to use a sub main. A better way (I guess maybe you could say the 2005 way) would be to leave the application framework enabled and don't use Sub Main

    So I guess you wanted to use sub main so that the first code to run when your app starts does not have to be a form, right?

    Go into your project properties, and select the first tab (application).
    click the "View Application Events" button and you will get a code screen where some events can be coded for that are global to your app (like when the app is opened, or closed, etc...)

    so you can write code in the MyApplication_Startup event instead of a submain.

    it even has event args like commandline params, or cancel, if you wanted to cancel the app from proceeding further (ie don't display your first form because a condition was not met)

    this would likely be the best solution, and would also not cause you to need to use application.enablevisualstyles, which has been buggy since it was introduced.

  5. #5

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Question about Sub Main()

    Thank you much, I originally was using a form as the initial item and still could but I didn't think that using sub Main would be such a headache. Thanks for the good info... rate up ^^
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] Question about Sub Main()

    Glad to help.
    I discovered all this when moving a 2003 app to 2005. The 2003 app had a sub main, and I didnt want to give it up, but I also wanted to gain the functionality of the application framework. That lead me to the application events.

    Because if you disable the application framework you lose some cool features that can make coding a bit easier at times

  7. #7

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [RESOLVED] Question about Sub Main()

    Hey I have a question about the application events. When I open that, it is just completely blank. I don't see where you were talking about the MyApplication_Startup event, do I need to create these?

    EDIT: Nevermind seems to just be in that project... wonder how i pooched that one haha oh well I will deal with it tomorrow
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] Question about Sub Main()

    it might have been caused from you turning off and back on the application framework

    if you need it, here is the IDE created code which is in ApplicationEvents.vb
    VB Code:
    1. Namespace My
    2.  
    3.     ' The following events are availble for MyApplication:
    4.     '
    5.     ' Startup: Raised when the application starts, before the startup form is created.
    6.     ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    7.     ' UnhandledException: Raised if the application encounters an unhandled exception.
    8.     ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
    9.     ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    10.     Partial Friend Class MyApplication
    11.  
    12.     End Class
    13.  
    14. End Namespace
    from there you select MyApplication Events from the left drop down at the top of the code view, and then you can select the events to program for from the right drop down (like like normal)

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