Simple question on forms

J

Joe Soap

Hello all
I am new to VB 2008..having come from VB6 after many years.

I have a problem unloading a form.

My frmLogin checks name/password against a database table (SQL Server 2005),
and if a match occurs, the form unloads (Close or Dispose), and shows
another form (frmSwitchboard ). Quite simple.

My code looks like this:
..............
..........
........
'*********************************************************************************************
'Assign the Loggers details to the variables

LogName = m_DataTable.Rows(0)("Name").ToString()

LogID = m_DataTable.Rows(0)("LogID").ToString()

'*********************************************************************************************

frmSwitchboard.Show()

Me.Close()

End If

End Sub

OK, the frmSwitchboard hows momentarily, before disappearing.

The Me.Close() also appears to be closing the frmSwitchboard as well.

I have a similar Me.Close statement on a button my frmSwitchboard , but the
frmSwitchboard opens up the form selected from frmSwitchboard button_click
and unloads frmSwitchboard .

I can't really see why frmLogin is also closing the frmSwitchboard. But what
do I know?

Anyone got any suggestions?

Best regards

David
 
T

Tom Shelton

Hello all
I am new to VB 2008..having come from VB6 after many years.

I have a problem unloading a form.

My frmLogin checks name/password against a database table (SQL Server 2005),
and if a match occurs, the form unloads (Close or Dispose), and shows
another form (frmSwitchboard ). Quite simple.

My code looks like this:
.............
.........
.......
'*********************************************************************************************
'Assign the Loggers details to the variables

LogName = m_DataTable.Rows(0)("Name").ToString()

LogID = m_DataTable.Rows(0)("LogID").ToString()

'*********************************************************************************************

frmSwitchboard.Show()

Me.Close()

End If

End Sub

OK, the frmSwitchboard hows momentarily, before disappearing.

The Me.Close() also appears to be closing the frmSwitchboard as well.

I have a similar Me.Close statement on a button my frmSwitchboard , but the
frmSwitchboard opens up the form selected from frmSwitchboard button_click
and unloads frmSwitchboard .

I can't really see why frmLogin is also closing the frmSwitchboard. But what
do I know?

Anyone got any suggestions?

Best regards

David

My guess is that the frmLogin is your startup form... The program will end
when the main form - your startup object closes.

It sounds in your case that the frmSwitchboard should really be the startup
object. It can show the login form in it's form load, and determine if the
login was succesfull (something like below - warning air-code!).

Class frmSwitchboard
Inherits System.Windows.Forms.Form

Private userName As String
Private userId As String

Private Sub frmSwitchboard_Load (ByVal sender As Object, ByVal e As EventArgs) Handles Form.Load
Using loginForm As New frmLogin()

If loginForm.ShowDialog(Me) = DialogResult.Ok Then
userName = loginForm.UserName
userId = loginForm.UserId
Else
Me.Close()
End If
End Using
End Sub
End Class

Anyway... HTH
 
J

Joe Soap

Thanks Tom

Quite right! DOH!!

Also, thanks for your suggestion re frmSwitchboard, that is a different way
to look at the app/programme loading.

This is just a practise programme whilst I get to grips with this new (for
me) language. Seems pretty up-hill at the moment!!

Thanks for your time

Best regards

David
 
O

Onur Güzel

Thanks Tom

Quite right! DOH!!

Also, thanks for your suggestion re frmSwitchboard, that is a different way
to look at the app/programme loading.

This is just a practise programme whilst I get to grips with this new (for
me) language. Seems pretty up-hill at the moment!!

Thanks for your time

Best regards

David












- Show quoted text -

Hi,
You can also try to set shutdown mode as "when last form closes" to
keep other forms alive from application tab of project settings.
See here:
http://i13.photobucket.com/albums/a272/u-might-want-this/ShutDown_Mode.jpg

HTH,

Onur Güzel
 
C

Cor Ligthert[MVP]

Joe,

See that Tom is using a Dialog, this is not so clear in Net as there is a
big difference of the behaviour of normal and dialogforms.

A normal form which is painted as you do it with show, will stay open. A
dialogform will wait until the form is closed (Like a dialog like
messagebox).

This makes that the method Tom shows is much easier, then what everybody
would go for first: open a form, and open a next form.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top