Hi Guys,

I am currently creating an application to track timekeeping (a clock in/out system) and I am trying to work out the best way to do this.

I have a Main Form which contains buttons to ;
- Log in
- Out for Break
- In from Break
- Log out

When a user presses the "log in" button the logon form appears, the user then enters their username and password. What happens next is where I would like the help.

Process is as follows:

  1. Click Logon
  2. Enter Username/Password
  3. Check Logon Form for errors (eg no password etc)
  4. Check User is in Database (using SQL query)
  5. If user is in DB and username and pass are ok then refer back to the main form to perform Stored Procedure for what the user wants to do (eg logon or or out for break etc).
  6. Set label on main form to show user as logged on

My question is should I be using a public variable and calling the main form again or in the user logon form having 4 options and using an IF ELSE to select the appropriate Stored Procedure?

Any help would be greatly appreciated, I have done a lot of searching for tutorials similar to this but cannot find any.

thanks in advance

6 Years
Discussion Span
Last Post by dwayned

Hi ,

Sorry I am only getting to post now, code that I am working with at the moment is below.

On Main Form (where user clicks Logon)

Public userlogon As Boolean
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Set to false for testing#
        UserLogon = False

        If userlogon = True Then
            'run the sp to log in/out...
            MsgBox("Logged in back to main", MsgBoxStyle.Critical)
            MsgBox("Error Logging In", MsgBoxStyle.Exclamation)
        End If
        'check user

    End Sub


When you click on the button it brings you to the logon form where user enters their username and password. Code for the ok button is below.

Code for Ok Button on Logon Form

Imports System.Data
Imports System.Data.SqlClient

Public Class LoginForm

    Dim con As New SqlConnection
    Dim cmd As New SqlCommand
    Dim MyDA As SqlDataAdapter
    Dim dataset As New DataSet

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        'Call UserLogon()
        If UserLogon() = True Then
            MsgBox("Sucessfully Logged In", MsgBoxStyle.Information)
        End If

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
    End Sub

    Public Function ValidateTxtBox() As Boolean

        If TxtBUsername.Text = "" And TxtBUsername.Text = "" Then
            MsgBox("Error - You Need to enter a Username & Password", MsgBoxStyle.Critical)
            ValidateTxtBox = True
        ElseIf TxtBUsername.Text = "" Then
            MsgBox("Error - Please Enter a Username", MsgBoxStyle.Critical)
            ValidateTxtBox = True
        ElseIf txtBPassword.Text = "" Then
            MsgBox("Error - Please Enter a Password", MsgBoxStyle.Critical)
            ValidateTxtBox = True
            ValidateTxtBox = False 'return false for errors
        End If

    End Function

End Class

The above Ok button calls UserLogon which is in a module. See below.

Module modVerifyUser
    Public ValidateTxtBox As Boolean

    Public Function UserLogon() As Boolean

        Dim IsError As Boolean
        Dim IsValidUser As Boolean

        IsError = ValidateTxtBox  'to get info from logon form if true
        IsValidUser = ValidateUser()

        If IsError = True Then                  'checks for blank text boxes
            Exit Function
            If ValidateUser() = False Then       'checks that user exists
                MsgBox("Error Logging on - Please check Username & Password and try again", MsgBoxStyle.Exclamation)
                'MsgBox("Sucessfully Logged In", MsgBoxStyle.Information)
                UserLogon = True
            End If
        End If
    End Function

    Private Function ValidateUser() As Boolean
        'this is where SQL will go to confirm user exists in DB
        'temp value for testing 
        ValidateUser = True

    End Function
End Module
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.