Click here to Skip to main content
15,891,692 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I need to create an application for school. The form needs to display command buttons that type in an alarm code.(1-9). I am specifically having troubles with reading which buttons the user clicks. This is what I have so far:

VB
Class Form1
    Private intCode As ArrayList
    Private Sub cmd0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd0.Click
        Dim cmd01 As String
        cmd01 = "0"
        intCode =
    End Sub
    Sub VerifyCode(ByVal intCode As String, ByVal intEntered As String)

        intCode = "62498"
        If intCode = intEntered Then
            MsgBox("Alarm Code Accepted")
        Else
            MsgBox("Incorrect Code, Please Try Again")
        End If
    End Sub
End Class
Posted
Updated 16-May-11 7:38am
v2

Well, it looks like you are an absolute beginner (that should sting a bit, but you kind of deserve it with a question like this), so let's keep it simple.
What I would do in your case (I believe the Form contains all information, including the correct code) is have a String field like this:
VB
Private _code As String

In each of you Button Event Handlers you can concatenate your string.
VB
' Do this for all Button.Click Events.
Private Sub cmd0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd0.Click
_code += "0"
End Sub

Private Sub btnVerify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVerify.Click
If _code = "62498" Then
' Accepted
Else
' Denied
End If
End Sub

Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
_code = String.Empty
End Sub


So first you build up the _code field in the different Button.Click Events. After that you can verify the code by comparing it to your access code. You can simply reset the password by emptying the String.
I guess I kind of did your homework for you.
And maybe you should read your books before coming here too...
 
Share this answer
 
I figured out a better way to do it. You see I'm not a beginner, but the difficult part was that I had to use a VerifyCode procedure with a intCode parameter. This is how I ended up doing it:

VB
Class Form1
    Sub VerifyCode(ByRef intCode As String)
        Dim alarmcode As String
        alarmcode = "62498"
        If intCode = alarmcode Then
            MsgBox("Passcode Accepted")
            Me.Close()
        Else
            MsgBox("Incorrect Passcode, Please Try Again")
        End If
    End Sub

    Private Sub cmd0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd0.Click
        Dim Zero As String
        Zero = "0"
        Me.txtcode.Text = Me.txtcode.Text & Zero
    End Sub

    Private Sub cmd1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd1.Click
        Dim One As String
        One = "1"
        Me.txtcode.Text = Me.txtcode.Text & One
    End Sub

    Private Sub cmd2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd2.Click
        Dim Two As String
        Two = "2"
        Me.txtcode.Text = Me.txtcode.Text & Two
    End Sub

    Private Sub cmd3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd3.Click
        Dim Three As String
        Three = "3"
        Me.txtcode.Text = Me.txtcode.Text & Three
    End Sub

    Private Sub cmd4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd4.Click
        Dim Four As String
        Four = "4"
        Me.txtcode.Text = Me.txtcode.Text & Four
    End Sub

    Private Sub cmd5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd5.Click
        Dim Five As String
        Five = "5"
        Me.txtcode.Text = Me.txtcode.Text & Five
    End Sub

    Private Sub cmd6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd6.Click
        Dim Six As String
        Six = "6"
        Me.txtcode.Text = Me.txtcode.Text & Six
    End Sub

    Private Sub cmd7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd7.Click
        Dim Seven As String
        Seven = "7"
        Me.txtcode.Text = Me.txtcode.Text & Seven
    End Sub

    Private Sub cmd8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd8.Click
        Dim Eight As String
        Eight = "8"
        Me.txtcode.Text = Me.txtcode.Text & Eight
    End Sub

    Private Sub cmd9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmd9.Click
        Dim Nine As String
        Nine = "9"
        Me.txtcode.Text = Me.txtcode.Text & Nine
    End Sub

    Private Sub cmdenter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdenter.Click
        Dim intCode As String
        intCode = Me.txtcode.Text
        Call VerifyCode(intCode)
    End Sub
End Class
 
Share this answer
 
Comments
Dave Kreskowiak 16-May-11 14:49pm    
With the code you've posted, you are most assuredly, a beginner.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900