none
What Dumb Error Causes This Simple App to Display Nothing? RRS feed

  • Question

  • I have been away from VB.Net and the IDE for a few years and must be repeating some beginner mistakes.  This really simple app produces no output.  There are no (longer) any build errors.

    Imports System
    
    Public Class Form1
    
        Sub Main()
    
            MessageBox.Show("Main entered")
    
            AddHandler HelpToolStripMenuItem.Click, AddressOf DisplayProdOverview
    
            MessageBox.Show("click handler added")
    
        End Sub
    
        Sub DisplayProdOverview()
    
            Dim wb As New WebBrowser
            Dim filename As String = "HTMLPage1.html"
    
            MessageBox.Show("click seen")
    
            With wb 'Change name to reflect your name
    
                .Url = New Uri(String.Format("file:///{0}{1}{2}/", System.IO.Directory.GetCurrentDirectory(),
                                             "/Resources/", filename))
            End With
        End Sub
    
    End Class

    I'll greatly appreciate any help.

    Bob

    Friday, February 23, 2018 2:45 PM

Answers

  • Well the Main routine is in the Form. Windows Forms already have a Main routine that is automatically generated by the compiler. Your custom Main routine is not going to execute unless there is something calling it. Usually Sub Main is in a Module and then you can select it as the startup object in your project properties.

    Here's more info on Sub Main:

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/main-procedure


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, February 23, 2018 3:14 PM
  • Hi

    Maybe the answer to your actual question is 'Bob' :)

    Here is your code, amended some, but working. Don't know about the file "HTMLPage1.html" though - but the code works in general. I added a ToolStrip and named it HelpToolStripMenu, added a few buttons etc, then processed the ToolStripButton2.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	MessageBox.Show("Main entered")
      End Sub
      Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
    	Dim wb As New WebBrowser
    	Dim filename As String = "HTMLPage1.html"
    	MessageBox.Show("click seen")
    	With wb 'Change name to reflect your name
    	  .Dock = DockStyle.Fill
    	  .Url = New Uri(String.Format("file:///{0}{1}{2}/", IO.Directory.GetCurrentDirectory(), "/Resources/", filename))
    	End With
    	Controls.Add(wb)
      End Sub
    End Class



    Regards Les, Livingston, Scotland


    Friday, February 23, 2018 3:28 PM
  • Hi eBob.com,

    You project is Winform, so you don't use sub main to start,  you can add these code in Form_load event or other Button_click Event.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            MessageBox.Show("Main entered")
            AddHandler HelpToolStripMenuItem.Click, AddressOf DisplayProdOverview
            MessageBox.Show("click handler added")
    
        End Sub
      

    Or

        Private Sub Form8_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            MessageBox.Show("Main entered")
            AddHandler HelpToolStripMenuItem.Click, AddressOf DisplayProdOverview
            MessageBox.Show("click handler added")
        End Sub

    If your project is console project, you need to use sub main() in Module.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by eBob.com Sunday, February 25, 2018 4:46 PM
    Saturday, February 24, 2018 6:46 AM
    Moderator

All replies

  • Well the Main routine is in the Form. Windows Forms already have a Main routine that is automatically generated by the compiler. Your custom Main routine is not going to execute unless there is something calling it. Usually Sub Main is in a Module and then you can select it as the startup object in your project properties.

    Here's more info on Sub Main:

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/main-procedure


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, February 23, 2018 3:14 PM
  • Hi

    Maybe the answer to your actual question is 'Bob' :)

    Here is your code, amended some, but working. Don't know about the file "HTMLPage1.html" though - but the code works in general. I added a ToolStrip and named it HelpToolStripMenu, added a few buttons etc, then processed the ToolStripButton2.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	MessageBox.Show("Main entered")
      End Sub
      Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
    	Dim wb As New WebBrowser
    	Dim filename As String = "HTMLPage1.html"
    	MessageBox.Show("click seen")
    	With wb 'Change name to reflect your name
    	  .Dock = DockStyle.Fill
    	  .Url = New Uri(String.Format("file:///{0}{1}{2}/", IO.Directory.GetCurrentDirectory(), "/Resources/", filename))
    	End With
    	Controls.Add(wb)
      End Sub
    End Class



    Regards Les, Livingston, Scotland


    Friday, February 23, 2018 3:28 PM
  • Hi eBob.com,

    You project is Winform, so you don't use sub main to start,  you can add these code in Form_load event or other Button_click Event.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            MessageBox.Show("Main entered")
            AddHandler HelpToolStripMenuItem.Click, AddressOf DisplayProdOverview
            MessageBox.Show("click handler added")
    
        End Sub
      

    Or

        Private Sub Form8_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            MessageBox.Show("Main entered")
            AddHandler HelpToolStripMenuItem.Click, AddressOf DisplayProdOverview
            MessageBox.Show("click handler added")
        End Sub

    If your project is console project, you need to use sub main() in Module.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by eBob.com Sunday, February 25, 2018 4:46 PM
    Saturday, February 24, 2018 6:46 AM
    Moderator
  • Thanks very much Paul, Les, and Cherry for your kind help.

    Bob

    Sunday, February 25, 2018 4:48 PM
  • Thanks for not giving my name. 

    I don't like people who first point to others and don't see that they made the problem themselves. 

    Most persons ask, "what did I do wrong". But you start with telling there is going on something Dump.

    It sounded for me as a guy who enters an Irish bar and ask if they have proper Bourbon instead of that Dumb Irish Whiskey. 


    Success
    Cor



    Sunday, February 25, 2018 5:00 PM
  • I don't publicly accuse others, and certainly not the .NET developers, of doing something dumb.  But I do use dumb often in describing myself.  In an effort to create a concise and succinct but eye catching subject perhaps I was careless in wording my subject.  What I meant was "What Dumb Error DID I MAKE Which is Causing My Simple App to Display Nothing?"  
    Sunday, February 25, 2018 6:51 PM
  • OK, that is the right way. 

    I remove my message by the way. 


    Success
    Cor

    Sunday, February 25, 2018 9:28 PM