close

標題:

 

此文章來自奇摩知識+如有不便請留言告知

VB輸入帳號密碼然後錯誤三次關閉程式

發問:

我們需要放2個label(代表帳號和密碼)然後兩個textbox (輸入帳號密碼用)以及一個button(輸入)請問以下這個程式碼要怎麼改才能輸入三次錯誤然後關閉呢以程式碼不做太大修改和表單項目不變為前提 Public Class Form1 Dim acc() = {"amy", "qwe", "asd", "zxc", "rty", "ffg", "vba", "row", "uio",... 顯示更多 我們需要放2個label(代表帳號和密碼) 然後兩個textbox (輸入帳號密碼用) 以及一個button(輸入) 請問以下這個程式碼要怎麼改才能輸入三次錯誤然後關閉呢 以程式碼不做太大修改和表單項目不變為前提 Public Class Form1 Dim acc() = {"amy", "qwe", "asd", "zxc", "rty", "ffg", "vba", "row", "uio", "jyu"} Dim pwd() = {"123", "456", "789", "741", "852", "963", "987", "654", "321", "753"} Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim pass As Boolean = False Dim p As Integer = 0 For i As Integer = 0 To UBound(acc) If LCase(TextBox1.Text) = acc(i) Then If TextBox2.Text = pwd(i) Then pass = True Exit For End If Next If pass Then MsgBox("歡迎登入!", , "通過") End Else MsgBox("帳號密碼錯誤!", , "錯誤") TextBox1.Text = "" TextBox2.Text = "" TextBox1.Focus() End If End Sub 更新: 請問 nError 是? 要宣告? 因為執行失敗

最佳解答:

Dim acc() = {"amy", "qwe", "asd", "zxc", "rty", "ffg", "vba", "row", "uio", "jyu"} Dim pwd() = {"123", "456", "789", "741", "852", "963", "987", "654", "321", "753"} Dim pass As Boolean = False Dim p As Integer = 0 Dim i, j As Integer For i = 0 To acc.Length - 1 If LCase(TextBox1.Text) = acc(i) Then For j = 0 To pwd.Length - 1 If TextBox2.Text = pwd(j) Then pass = True Exit For Next End If If pass Then Exit For End If Next If pass Then MsgBox("歡迎登入!", , "通過") Else nError += 1 MsgBox("帳號密碼錯誤!", , "錯誤") TextBox1.Text = "" TextBox2.Text = "" TextBox1.Focus() If nError = 3 Then Me.Close() End If End If 2012-04-20 10:41:31 補充: 吼兒 說的全域變數,這是留給你debug的, 你要知道變數的生命週期的原理跟運用, 如果你想走程式這一行的話,你的基礎要很清楚明瞭。

其他解答:

請問可以打程式碼嗎?|||||用個全域變數計次 錯誤就加一 當等於三時ENDCF546184287637C5

arrow
arrow
    創作者介紹
    創作者 thhzpvx 的頭像
    thhzpvx

    thhzpvx的部落格

    thhzpvx 發表在 痞客邦 留言(0) 人氣()