how can i load a form from a module created in d same project??...........What function should i use to do so???

Dani AI

Generated

The short answer depends on which Visual Basic is used: the thread mixes older VB patterns and VB.NET patterns, so the right call varies. Replies from and point toward simply invoking a form’s show behavior, and showed a Sub Main wrapper — but that wrapper mixes idioms and can leave readers unsure whether they’re in VB6 or VB.NET.

For VB.NET Windows Forms projects the safe pattern when using a Module/Sub Main as the startup object is to start the Windows message loop explicitly and create form instances. A typical Sub Main will enable visual styles and call the framework run method to show the main window:

Sub Main()
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
    Application.Run(New MainForm())
End Sub

For additional windows opened from a Module, create a new instance and show it modally when a blocking dialog is needed:

Sub OpenSettings()
    Dim dlg As New SettingsForm()
    dlg.ShowDialog()
    dlg.Dispose()
End Sub

VB6 behaves differently: it supports an explicit preload step separate from display (useful for initializing controls before the form appears). Modules can call those VB6 statements directly, but the project type and startup object must match that model.

Troubleshooting and best practices: confirm the project type and startup object, ensure UI creation happens on the UI thread, avoid holding unnecessary global form references, and Dispose modal forms when done. For details on starting a WinForms app from Sub Main, default form instances, and how to set the startup object see the Microsoft docs: Application.Run documentation, , and .

Recommended Answers

All 3 Replies

Load formname

in the module paste the following code :-(the bolded parts only)

sub to load the form specified by you
Private Sub loadForm(frm As Form)
Load frm
frm.Show
End Sub

this is the main function that a module should have while you are trying to execute it from your project as a startup object

Sub main()
Call loadForm(Form1)
End Sub

where form1 is the name of the form you wish to load. after finishing the coding goto project->project properties->set sub main() from startup object->click ok->run the project

Hi,

Use :

Form1.Show

It will Load and Show (Not necessary to Load and Show)

Regards
Veena

how can i load a form from a module created in d same project??...........What function should i use to do so???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.