Link to home
Start Free TrialLog in
Avatar of systems_ax
systems_ax

asked on

login screen in visual basic 2005

every time my login screen comes up, it comes up behind the splash screen. I have  tried changing this code around under the "application events", but it still comes up behind the splash screen.  so, when I deploy the application, I have a splash screen open up, which hangs and behind it there is a login form, so unless I open the login form from the task bar, it will not come up.
And the "close button" on the login screen "does not close the form", what it does is it opens the main window.  I do have "me.close" under the "close button"
Can you please help, I have included the code for both the "application events" and "the login form itself"?
Thank you, I am coding in visual basic 2005 with access 2007 database.


application events
 
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Windows.Forms
 
Namespace My
    ' The following events are availble for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication
        ' Override OnInitialize to set the splash screen's
        Protected Overrides Function OnInitialize(ByVal commandLineArgs As _
          System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
            ' Display the splash screen for at least 6 seconds.
            Me.MinimumSplashScreenDisplayTime = 6000
            ' Continue initialization as usual.
            Return MyBase.OnInitialize(commandLineArgs)
        End Function
 
        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            
 
 
            Dim splash_screen As SplashScreen1
            splash_screen = DirectCast(My.Application.SplashScreen, SplashScreen1)
            'Wait one second three times.
            For progress As Integer = 0 To 100 Step 10
                Dim stop_time As Date = Now.AddSeconds(0.25)
                Do While Now < stop_time
                    Application.DoEvents()
                Loop
            Next progress
 
 
            Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb")
            Dim reader As OleDbDataReader
 
            conn.Open()
            Dim query As String = "SELECT * FROM tblUsers"
            Dim cmd As OleDbCommand = New OleDbCommand(query, conn)
            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
 
            If reader.HasRows Then
                'MessageBox.Show("Valid login")
                Dim formLogin As New LoginUser
                formLogin.ShowDialog()
                'Dim formMain As New Main
                'formMain.Close()
            Else
            End If
            conn.Close()
            reader.Close()
            'Catch ex As Exception
            '    MessageBox.Show(ex.Message)
            'Finally
            '    If conn.State = ConnectionState.Open Then
            '        conn.Close()
            '    End If
            '    reader = Nothing
            '    conn = Nothing
            'End Try
        End Sub
    End Class
End Namespace
 
 
 
the actual "login" form:
 
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Windows.Forms
 
Public Class LoginUser
 
    Public Event Login As EventHandler
    Dim tryNumber As Integer
        Private ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb"
 
 
    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.
 
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
 
           If (txtUserName.Text.Trim() = "") Then
            MsgBox("User Id cannot be left blank.", MsgBoxStyle.Critical)
            txtUserName.Text = ""
            txtPassword.Text = ""
            txtUserName.Focus()
            Exit Sub
        ElseIf (txtUserName.Text.Trim.Length > 10) Then
            'MsgBox(TextBox1.Text.Trim.Length)
            MsgBox("User Id cannot be more than 10 characters.", MsgBoxStyle.Critical)
            txtUserName.Text = ""
            txtPassword.Text = ""
            txtUserName.Focus()
            Exit Sub
        End If
 
        If (txtPassword.Text.Trim() = "") Then
            MsgBox("Password cannot be left blank.", MsgBoxStyle.Critical)
            txtPassword.Text = ""
            txtPassword.Focus()
            Exit Sub
        ElseIf (txtPassword.Text.Trim.Length > 10) Then
            MsgBox("Password cannot be more than 10 characters.", MsgBoxStyle.Critical)
            txtPassword.Text = ""
            txtPassword.Focus()
            Exit Sub
        End If
 
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb")
        Dim reader As OleDbDataReader
        Try
            conn.Open()
            Dim query As String = "SELECT * FROM tblUsers WHERE fldUserName = """ & txtUserName.Text & """ AND fldPassword = """ & txtPassword.Text & """"
            Dim cmd As OleDbCommand = New OleDbCommand(query, conn)
            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            If reader.HasRows Then
                'MessageBox.Show("Valid login")
                Dim formMain As New Main
                formMain.Show()
                Me.Close()
            Else
                MessageBox.Show("The username or password are not valid!")
            End If
            conn.Close()
            reader.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If
            reader = Nothing
            conn = Nothing
        End Try
        
    End Sub
 
   
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
 
    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of systems_ax
systems_ax

ASKER

jpaulino,
do I delete the following code on the splash screen?

 Me.MinimumSplashScreenDisplayTime = 6000
For progress As Integer = 0 To 100 Step 10
                Dim stop_time As Date = Now.AddSeconds(0.25)
                Do While Now < stop_time
                    Application.DoEvents()
                Loop
            Next progress

Thank you very much
Yes, you don't need that. The timer will do the same for you.
jpaulino,
I believe I did exactly what you said and now have a splash screen on my machine that will not go away, I even uninstalled the software already.
Here is my code, maybe you can see something that I can't.  I'l; be working on this issue until I get it right.
thank you

this is my APPLICATION EVENTS:
i DO NOT HAVE ANY CODE IN IT AND i SET  THE FOLLOWING
Startup Form = SplashScreen1
   Shutdown mode = When last form closes
   Splash Screen = None

THIS IS MY SPLASH SCREEN FORM:
 
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Windows.Forms
 
Public NotInheritable Class SplashScreen1
    'TODO: This form can easily be set as the splash screen for the application by going to the "Application" tab
    '  of the Project Designer ("Properties" under the "Project" menu).
    Private myTimer As Timer
 
    Private Sub DoTimerWork(ByVal sender As Object, ByVal e As System.EventArgs)
 
        myTimer.Enabled = False
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb")
        Dim reader As OleDbDataReader
 
        conn.Open()
        Dim query As String = "SELECT * FROM tblUsers"
        Dim cmd As OleDbCommand = New OleDbCommand(query, conn)
        reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
 
        If reader.HasRows Then
           Dim formMain As New LoginUser
            formMain.ShowDialog()
           Else
        End If
        conn.Close()
        reader.Close()
        ' Stops the timer
        'myTimer.Enabled = False
 
        '' Checks the next option
        'Dim frm As Form
        'If YourCondition Then
        '    frm = New Main
        'Else
        '    frm = New Main
 
        'End If
        'frm.Show()
        'Me.Close()
 
    End Sub
 
    Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        myTimer = New Timer
        myTimer.Interval = 2000
        myTimer.Enabled = True
        AddHandler myTimer.Tick, AddressOf DoTimerWork
 
        If My.Application.Info.Title <> "" Then
            'ApplicationTitle.Text = My.Application.Info.Title
        Else
            'If the application title is missing, use the application name, without the extension
            'ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
        End If
 
      End Sub
 
    Public Sub New()
 
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
 
    End Sub
End Class

Open in new window

Ok, now what's the problem ?
jpaulino,
I figured it out, the program works perfectly.  Thank you very much for your help.