Results 1 to 2 of 2

Thread: I need help

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2021
    Posts
    1

    I need help

    I have been working on this user validation code for over 6 hours and cannot get it to work. There are 3 users that are hardwired in there and and error user. However, when I click the button it does not run the code or even display an error message. Ill post my code below and I just need another set of eyes to see what could be fixed. I am using VB 2017 with windows form.
    Code:
    Public Class frmID
        Private Sub btnAuthenticate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAuthenticate.Click
            'Declarations
            'Constants
            'First Names
            Const strKaz As String = "Kaz"
            Const strEmika As String = "Emika"
            Const strNesta As String = "Nesta"
            Dim strNotFirstName As String
    
            'Last Names
            Const strBrekker As String = "Brekker"
            Const strChen As String = "Chen"
            Const strArcheron As String = "Nesta"
            Dim strNotLastName As String
    
            'Emails
            Const strKazEmail As String = "kaz.brekker@crowclub.com"
            Const strEmikaEmail As String = "emika.chen@warcross.com"
            Const strNestaEmail As String = "nesta.archeron@valkyrie.com"
    
            'ID
            Const decKazID As Decimal = 4800587568
            Const decEmikaID As Decimal = 4800598746
            Const decNestaID As Decimal = 4800215649
    
            'Full Names
            Const strKazFullName As String = strKaz + strBrekker
            Const strEmikaFullName As String = strEmika + strChen
            Const strNestaFullName As String = strNesta + strArcheron
    
            'Success and Fail
            Dim strSuccess As String
            Dim strFail As String
            Dim strNotFound As String
    
            'Error
            Dim strError As String
    
            'authenticate
            Dim authenticate As String
    
            'Input
            'Strings
            strSuccess = "Success"
            strFail = "Fail"
            strNotFound = "User Not Found"
    
            'Error
            strNotFirstName = txtFirst.Text
            strNotLastName = txtLast.Text
            strError = strNotFirstName + strNotLastName
    
            'authenticate
    
            'Processing
            'Case of people
            Select Case authenticate
                Case Is = strKazFullName
                    If txtID.Text = strKazEmail Or decKazID Then
                        'Output
                        lblAuthenticate.Text = strSuccess.ToString
                    Else
                        'Output
                        lblAuthenticate.Text = strFail.ToString
                    End If
                Case Is = strEmikaFullName
                    If txtID.Text = strEmikaEmail Or decEmikaID Then
                        'Output
                        lblAuthenticate.Text = strSuccess.ToString
                    Else
                        'Output
                        lblAuthenticate.Text = strFail.ToString
                    End If
                Case Is = strNestaFullName
                    If txtID.Text = strNestaEmail Or decNestaID Then
                        'Output
                        lblAuthenticate.Text = strSuccess.ToString
                    Else
                        'Output
                        lblAuthenticate.Text = strFail.ToString
                    End If
                Case Is = strError
                    'Output
                    lblAuthenticate.Text = strNotFound.ToString
            End Select
    
        End Sub
    End Class
    Last edited by Shaggy Hiker; Sep 17th, 2021 at 03:36 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: I need help

    That subject line isn't all that good. Anybody who posts a question here generally needs help. I also edited your post to add [CODE][/CODE] tags, which you can do by pressing the # button and pasting the code between the resulting tags.

    As to the question, have you put a breakpoint in the code? Is it hit?

    There certainly seems to be a clear problem in the code, since the switch uses the authenticate variable, and that variable isn't being set to anything, but from your description, the problem seems to arise even earlier. You say that it does not run the code. That code won't DO anything visible because of that issue with the variable, but if you have put a breakpoint in the code, and it isn't hit, then there's an earlier problem.

    Another part of the issue is that there is no 'else' in that switch case. The authenticate variable MUST match one of those strings exactly. Most likely, it could never match the strError, nor would you want it to, so that should be a Case Else. Because there is no Case Else, then if authenticate doesn't exactly match one of the cases, then nothing will happen, and since authenticate is empty, then it seems like nothing could ever happen.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width