Question Textbox not displaying in Sub Main()

Eebigdog

Member
Joined
Sep 13, 2013
Messages
5
Programming Experience
10+
Hello,

Simple problem (I think) but, the textbox call in my Sub Main() doesn't want to display anything:Sub Main()
Form1.Show()
Form1.TextBox1.Text = "Ready"

End Sub


The textbox does display other items later on in the code just not in main.
What's the problem?

Thanks,
Grant
 
If that Main method was the entry method for your application then your app would exit immediately so obviously it's not, therefore it should not be called Main. ONLY use Main as the application entry point, which is hidden from you by default. Where exactly is that code located and what exactly are you trying to achieve?
 
Hi jmc,

Sub Main() is in a module (Module1.vb). Form1.vb has a button, a textbox and a listbox.
I just want the user to know that the code is running and ready for them to use the button.

BTW - Isn't main needed to enable my Form1 via the "Form1.Show()" command?

Thanks,
Grant
 
I think you'll find that the reason that that text is not appearing is that that code is not even being executed. Place a breakpoint on it using the F9 and see if it gets hit to see for yourself.

Yes, you do need a Main method as the entry point for your app but, as I said previously, that Main method is not being used as the entry point. In VB.NET Windows apps since VB 2005, some called the Application Framework is enabled by default. That does various things for you, including creating a Main method. In order to use your own Main method as the application entry point, you must first disable the Application Framework. You can then specify a form or module containing a Main method as your startup object.

If you actually did use that Main method of yours as the entry point for the app though, your app would exit immediately because there's no blocking call in there. Show returns immediately so you would display the form, display the text and then the Main method would complete and your app would exit. In a proper Main method you call Application.Run, which blocks until the specified form is closed, which is why closing the startup form closes the app.
 
I just want the user to know that the code is running and ready for them to use the button.
Surely the very appearance of the form signifies that.
 
Back
Top