• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Visual Basic HELP

Joined
Feb 11, 2008
Messages
612 (0.10/day)
Location
DFW, Texas, USA
System Name Built By Me
Processor AMD 9800X3D
Motherboard Gigabyte X870 Aorus Elite WiFi7
Cooling Water Cooling - CPU Only - Heatkiller IV Pro - TG PhaseSheet PTM
Memory 32GB (2 x 16) - GSkill FlareX5 DDR5 6000 Mhz
Video Card(s) RTX 4080 - ASUS ROG Strix 16GB OC - P Mode
Storage 2TB Inland Performance Plus NVMe
Display(s) Alienware AW2723DF @ 280 Hz @ 1440P
Case Fractal Design Define S2
Audio Device(s) Corsair Virtuoso Pro Headset
Power Supply 1000W MSI MPG A1000G PCIE5
Mouse Razer Viper V3 Pro @ 2k Hz
Keyboard Asus ROG Strix Scope II 96 Wireless - ROG NX Snow Switches
Software Windows 11 Pro
I use VB 2008 Express Edition, and I cannot get my multiple form application to work correctly. I am trying to get frmNext to show up after frmInput is done. So, in frmInput's button click event, I type in strName = TextBox1.Text, frmNext.Show(), and Unload frmInput. Unload does not work in vb 2008 anymore I guess, because it gave me an error. So, I typed in Me.Close(), which closes the application altogether. So, I decided to go into frmNext's form load event and type in Me.Text = strName and frmInput.Close(), which causes the entire program to close. I need help getting frmNext to show up and frmInput to close down.
 
Ah im not that great yet but could you post the whole code? I could probly help ive been using it for a few years now.
 
Option Explicit On
Module Module1
Public strName As String
End Module

Option Explicit On
Public Class frmInput

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
strName = TextBox1.Text
frmNext.Show()
Me.Close()

End Sub
End Class

Option Explicit On
Public Class frmNext

Private Sub frmNext_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = strName
End Sub
End Class
 
Create a module with a Sub "Main"
Code:
Imports System.Windows.Forms

Module Module1
  Sub Main()
    Dim frmInput as new FormInput
    frmInput.Show()
    Application.Run() // This starts the App without a start-up main form
  End Sub
End Module

In the Input Form (which will load as the default form)
Code:
Private closeApp as Boolean = True

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles Button1.Click
  closeApp = False;
  Dim nextFrm As New NextForm
  nextFrm.Show()
  Me.Close()
End Sub

// Just in case you want to kill the App from this form
Private Sub InputForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
   If closeApp Then
      Application.Exit()
   End If
End Sub

In Next Form, use something like this to close the Application
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Application.Exit()
End Sub

This is not the most robust way of doing this, but it should work for you.
 
Whenever I wanted to do something like that back in the day, i'd simply change the visibility of the form

frm.setVisible(true); to display it
frm.setVisible(false); to hide it
 
Whenever I wanted to do something like that back in the day, i'd simply change the visibility of the form

frm.setVisible(true); to display it
frm.setVisible(false); to hide it

That works okay, but then you have unneeded components and their associated resources hanging around eating up stack and heap space (RAM). It is better to dispose of the unneeded resource so that the garbage collector can clean up after you.
 
After some quick perusing ...

You may just be able to go into your projects properties page, and under the Application tab set the "Shutdown mode" to "After last form closes" instead of the default "When main form closes".
 
Back
Top