新手 vb 2005 功課 請教大家~

Home Home
引用 | 編輯 soloman124
2006-12-07 18:57
樓主
推文 x0
要求
Try to modify the program such than when user fail to input correct password more than 3 time, an error message will be displayed and does not allow user to try any more.

如何 ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 nomaid
2006-12-07 21:00
1樓
  
複製程式
dim wrongval as integer '定義wrongval 為integer
Dim username, password As String
Dim LoginSuccess As Boolean = False

wrongval = 0 '將wrongval 預設等於0 

Do Until LoginSuccess
 username = InputBox("Username Please")
 password = InputBox("Password Please")


 If username = "Peter" And password = "1234" Then
  LoginSuccess = True
else
  wrongval +=1 ' 判斷如果不等於的話 則wrongval + 1
 End If

 if wrongval >3 then                           ' 判斷如果錯誤次數超過3則秀出彈跳視窗
    messagebox.show("已輸入三次錯誤!!")
 end if
Loop

MsgBox ("Login success")


不曉得你要的錯誤畫面是什麼 隨便寫了一段 你自己看看吧
有附加說明 有問題的話 可以PM詢問~

獻花 x1
引用 | 編輯 soloman124
2006-12-07 21:50
2樓
  
下面是引用nomaid於2006-12-7 21:00發表的 :
[code]dim wrongval as integer '定義wrongval 為integer
Dim username, password As String
Dim LoginSuccess As Boolean = False

.......
多謝解答
唔明再問你

感激^__^

獻花 x0
引用 | 編輯 soloman124
2006-12-07 23:20
3樓
  
下面是引用nomaid於2006-12-7 21:00發表的 :
[code]dim wrongval as integer '定義wrongval 為integer
Dim username, password As String
Dim LoginSuccess As Boolean = False

.......
有bug 當三次失敗後再次成功時兩者都會 彈出成功和成敗@@

獻花 x0
引用 | 編輯 nomaid
2006-12-08 00:59
4樓
  
你自行再判斷錯誤次數是否大於三後面加上中斷跳出的指令 (exit do)就可以了^^"

複製程式
 if wrongval >3 then                           ' 判斷如果錯誤次數超過3則秀出彈跳視窗
    messagebox.show("已輸入三次錯誤!!")
    exit do                                          ' 新增的語法位置..
 end if


獻花 x0
引用 | 編輯 soloman124
2006-12-08 19:59
5樓
  
下面是引用nomaid於2006-12-8 00:59發表的 :
你自行再判斷錯誤次數是否大於三後面加上中斷跳出的指令 (exit do)就可以了^^"

[code] if wrongval >3 then                   ' 判斷如果錯誤次數超過3則秀出彈跳視窗
  messagebox.show("已輸入三次錯誤!!")
.......
exit do 是點解?
多謝你
但我想知為什麼加me.close()
不能關閉 ?

獻花 x0
引用 | 編輯 nomaid
2006-12-09 00:06
6樓
  
exit do 的意思 就是離開do迴圈 直接離開你的迴圈判斷 並且跳出你輸入三次錯誤的視窗

me.close() => 我都是直接下 close() 這樣比較簡略

程式寫法有很多種 不只我這種寫法 你自己可以再去想想其他的寫法

你應該再多去找找相關的程式教學網站 或是 多看點書 才會對你有幫助

獻花 x0