如何在vb.net中创建安全警报系统? [英] How do I create a security alarm system in vb.net?

查看:62
本文介绍了如何在vb.net中创建安全警报系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为学校创建一个应用程序.表单需要显示键入警报代码的命令按钮.(1-9).我特别在阅读用户单击哪个按钮时遇到麻烦.这是我到目前为止的内容:

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:

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

推荐答案

好吧,看来您是个绝对的初学者(应该有点刺痛,但您应该通过这样的问题得到它),所以让我们保持简单.
在您的情况下(我相信表单包含所有信息,包括正确的代码),我将做一个String字段,如下所示:
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:
Private _code As String


在每个按钮事件处理程序中,您都可以连接字符串.


In each of you Button Event Handlers you can concatenate your string.

' 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



因此,首先您要在其他Button.Click事件中建立_code字段.之后,您可以通过将代码与访问代码进行比较来验证代码.您只需清空字符串即可重置密码.
我想我为你做了功课.
也许您也应该在来这里之前阅读您的书...



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...


我想出了一种更好的方法.您会看到我不是初学者,但困难的部分是我必须使用带有intCode参数的VerifyCode过程.这就是我最终做的方式:

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:

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


这篇关于如何在vb.net中创建安全警报系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆