標題:
- 100年統測470可以上哪裡?
- 台灣大哥大528賺錢達鈴
- EXCEL 處理有二個欄位查詢及第三個欄位加總 SUMIF.
- 寒假作業 國英數自一些問題
- P4 1.8A 和celeron D 2.4 CPU比較-
- 冷氣一對二的室外機和室內機要多少錢?
- 98四技二專登記分發
- [急!!20點]我有一個男生朋友生日!想送親手作的禮物!!
- 如何解決PLC加和減溢位問題-------
- 小6數學5題!!
此文章來自奇摩知識+如有不便請留言告知
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
留言列表