locked
Visual Basic Class RRS feed

  • Question

  • User-812600381 posted

    Have an issue trying to figure out the code to work for this program. I think I did everything as described fir the project but I'm stuck in a particular section.

    This is my Instructor Feedback: The code in step 8 of this project was not coded properly (the VerifyUsername and VerifyPassword Functions) There should be more code in the Functions besides Return True!

    I know where it needs to be inserted but can't figure out how to make it work?

    Monday, April 19, 2021 12:34 AM

All replies

  • User-1330468790 posted

    Hi Pogwuda,

      

    Thank you for your questions and welcome!

    Could you please share the steps of creating the project? 

    Or you can post the codes for functions (VerifyUsername and VerifyPassword ) so that we can find out why your instructor suggests you add more codes.

    Baed on your description, I can only guess that you might need to 

    1. add return false for some conditions
    2. add some codes to make it a function (miss End key word)

      

    Hope helps.

    Best regards,

    Sean

    Monday, April 19, 2021 2:40 AM
  • User-812600381 posted

    Hi Sean, 

    Thanks for the welcome and your response. It is most appreciated. 

    How do I post/paste the Form that I have worked on with the instructions I followed on here if I may ask? Was trying to copy/paste but it does not allow me to.

    Monday, April 19, 2021 12:21 PM
  • User-812600381 posted

    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin", "Clerk", "Manager"}
        Dim arrPasswords() As String = {"P@ssword", "pa$$word", "passwOrd"}

        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                'Find Index for username
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
                'Check for password match
                If arrPasswords(userIndex) = password Then
                    blnLoggedIn = True
                Else
                    MessageBox.Show("Incorrect password.")
                End If
            End If
        End Sub
        Function VerifyUsername(username As String) As Boolean
            'If the username is found, Return True, otherwise Return False
            Return True
        End Function
        Function VerifyPassword(password As String) As Boolean
            'If the passwords match, Return True, otherwise Return False
            Return True
        End Function
    End Module

    Monday, April 19, 2021 11:06 PM
  • User-812600381 posted

    Public Class LoginForm
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles lblUsername.Click, btnLogin.Click
            Main.Login(txtUsername.Text, txtPassword.Text)
            If Main.blnLoggedIn Then
                MessageBox.Show("Thank you for logging in, " & txtUsername.Text, "Logged In.")
                Me.Close()
            End If

        End Sub

        Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
            Application.Exit()

        End Sub

        Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

        End Sub
    End Class

    Monday, April 19, 2021 11:08 PM
  • User-812600381 posted

    1. In Visual Studio, load the GroceryApp project that you completed in Lesson 1.
    If this isn’t available, then you’ll need to ask your instructor for the finished
    Lesson 1 project.
    2. Add a new module to the project.
    a. Right-click the project name in Solution Explorer and choose Add >
    Module... or choose the Add Module... option in the Project menu.
    b. Type the name Main.vb in the Name text box at the bottom. An example
    of what the screen should look like is shown in Figure 13.
    c. Click the Add button.
    3. In the Main module, you’ll perform the following actions.
    a. Declare a Boolean variable named blnLoggedIn.
    b. Declare two String arrays named arrUsernames and arrPasswords.
    c. Declare a subroutine named Login that accepts two String parameters
    named username and password.
    d. Declare two functions named VerifyUsername and VerifyPassword.
    The VerifyUsername function should accept a String parameter named
    username and return a Boolean value. The VerifyPassword function
    should accept a String parameter named password and return a Boolean
    value. When this task is completed, the source code editor should contain
    the code shown in Figure 14.
    © PENN FOSTER, INC. 2017 VISUAL BASIC PROGRAMMER PAGE 56
    Graded Project
    FIGURE 14—Source Code Editor with Correct Code
    FIGURE 13—Enter Main.vb in the location where modVerify.vb is shown and
    click Add.
    © PENN FOSTER, INC. 2017 VISUAL BASIC PROGRAMMER PAGE 57
    Graded Project
    4 Save your work.
    5. Use the values Admin, Clerk, and Manager as items in the arrUsernames array.
    Use the assignment operator and curly braces to modify the declaration as follows:
    Dim arrUsernames() As String 5 {“Admin”, “Clerk”, “Manager”}
    6. Use the values P@ssword, pa$$word, and passw0rd as items in the arrPasswords array. Use the assignment operator and curly braces to modify the
    declaration as follows:
    Dim arrPasswords() As String 5 {“P@ssword”, “pa$$word”,
    “passw0rd”}
    7. In the Login subroutine, make sure that the username and password arguments
    are valid and match.
    a. Set the blnLoggedIn variable to False. This is to ensure that previous
    attempts are overwritten.
    b. Use an If...Else statement. Using the logical operator And, combine
    the return value from calling the VerifyUsername and VerifyPassword
    functions.
    c. If the username and password arguments are valid, then make sure the
    value in the arrUsernames array matches the value in the arrPasswords
    array.
    d. If the correct password is specified for the username, then set the
    blnLoggedIn variable to the value True. If not, then display an error
    message box.
    e. When the task is complete, the Login function should be defined as
    follows:
     Sub Login(username As String, password As String)
    blnLoggedIn 5 False
    If VerifyUsername(username) And VerifyPassword(password)
    Then
    ‘Find index for username
    Dim userIndex As Integer
    For loopIndex 5 0 To arrUsernames.Length - 1
    If arrUsernames(loopIndex) 5 username Then
    userIndex 5 loopIndex
    Exit For
    End If
    Next
    © PENN FOSTER, INC. 2017 VISUAL BASIC PROGRAMMER PAGE 58
    Graded Project
    ‘Check for password match
    If arrPasswords(userIndex) 5 password Then
    blnLoggedIn 5 True
    Else
    MessageBox.Show(“Incorrect password.”)
    End If
    End If
    End Sub
    8. Using what you know about search arrays, implement the VerifyUsername and
    VerifyPassword functions. They should return true if the username or password is
    found in the arrUsernames or arrPasswords array, respectively.

    Monday, April 19, 2021 11:11 PM
  • User-812600381 posted

    Good Evening!

    I posted the instructions, the Main module and the Login Module of the project and the codes used according to the instructions. Line 8 of the instructions is where I'm stuck

    Monday, April 19, 2021 11:15 PM
  • User-1330468790 posted

    Hi Pogwuda,

     

    8. Using what you know about search arrays, implement the VerifyUsername and
    VerifyPassword functions. They should return true if the username or password is
    found in the arrUsernames or arrPasswords array, respectively.

    As you can see that in your codes, you don't implement two functions, VerifyUsername and VerifyPassword, but simply leave them to return "true".

    Based on the instructions, they will only return "true" if the username or password is found in the arrUsernames or arrPasswords array, respectively.

    For example,

     Function VerifyUsername(ByVal username As String) As Boolean
    'If the username is found, Return True, otherwise Return False For Each un In arrUsernames If username = un Then Return True End If Next Return False End Function Function VerifyPassword(ByVal password As String) As Boolean
    'If the passwords match, Return True, otherwise Return False For Each pw In arrPasswords If password = pw Then Return True End If Next Return False End Function

     

    Hope helps.

    Best regards,

    Sean

    Tuesday, April 20, 2021 7:27 AM
  • User-812600381 posted

    Hi Sean,

    I see what you're saying. So I should just type in the code as it is above and it should work then? And if I may ask, what is 'un'. I just started this class but this is self taught so I'm learning as I go

    Thanks

    Wednesday, April 21, 2021 12:14 AM
  • User-1330468790 posted

    Hi Pogwuda,

     
    As your project looks like a WinForms and here is a ASP.NET forum, I can not gurantee that your application will run successfully. 

    What I am sure is that the functions I provided you with should work as expect => to search values in an array.

    8. Using what you know about search arrays, implement the VerifyUsername and
    VerifyPassword functions. They should return true if the username or password is
    found in the arrUsernames or arrPasswords array, respectively.

     

    If you have any question running this application, you can start from below documentation to make it work.

    Create a Windows Forms app in Visual Studio with Visual Basic

     

    Best regards,

    Sean

    Wednesday, April 21, 2021 3:40 AM