[VB6 ] 杞人憂天..

看板Visual_Basic作者 ([αλφα])時間18年前 (2007/01/10 17:43), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
(程式碼在下面) 我寫了一個函式來判斷是否所有該輸入的資料都輸入的正確無誤, 利用回圈來判斷。 原本沒有那個 Exit For的,(紅色文字) 後來因為發現,假使使用者有錯不只一個地方, 那麼錯誤訊息就會彈出不止一次... 因此我就加了Exit For,在發現一次錯誤之後,就跳出回圈, 這樣就只會跳出一次錯誤訊息。 但是後來想想,這樣跳出來的時候,感覺上 If CheckInput(i) = 1 這邊, 沒有一個結尾...感覺有點怕怕的@@" 感覺就像是使用未定義過的變數一樣== 雖然測試是沒有錯誤...但是不太敢肯定..囧 在想需不需要在Exit For前面加上一個 End If (黃色文字)? 還是說,直接用Exit For就可以幫你結束If? 因為沒有基礎所以沒有自信...囧 因此就杞人憂天了...囧 -- Function AllOK() As Boolean Dim i, check As Integer For i = 0 To 14 If CheckInput(i) = 1 Then check = 1 SendMsg (End If) Exit For End If Next i If check = 1 Then AllOK = False Else AllOK = True End Function -- "Every kid who has dreamed of being a baseball player has stood in his front yard with a bat and said to himself, "Bottom of the ninth, Game 7 of the World Series, the bases are loaded," and then envisioned hitting a home run to win the game. My job is to shatter that dream." By Huston Street -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.8.68.154 ※ 編輯: A1pha 來自: 124.8.68.154 (01/10 17:44)

01/10 18:28, , 1F
突然想到...好像可以用 do Until....loop 囧
01/10 18:28, 1F

01/10 18:29, , 2F
這樣就不需要用Exit For了
01/10 18:29, 2F

01/12 06:33, , 3F
不需要多打 end if...
01/12 06:33, 3F
文章代碼(AID): #15fBKjre (Visual_Basic)
文章代碼(AID): #15fBKjre (Visual_Basic)