例如VB上面出現1234四個數字
用鍵盤按1234從按1開始計時到按到4結束計時
如果可以最好給範例題
2006-06-11 05:51:33 · 1 個解答 · 發問者 lin 1 in 電腦與網際網路 ➔ 程式設計
'以下是VB6語法,我把此題做成類似英打練習程式Dim D As Double, S As String, S1 As String, B As BooleanPrivate Sub Form_KeyPress(KeyAscii As Integer) Dim A As String, I As Integer, N As Integer, X As Integer If B Then 'B=True表示解題中 A = UCase(Chr(KeyAscii)) '按鍵值 '若按鍵值跟S1第1字相同就移除S1第1字,直到S1="" If A = Left(S1, 1) Then S1 = Right(S1, Len(S1) - 1) Print A; " "; End If If Len(S1) = 0 Then Print 'Timer - D表示花費的時間 Print "共費時 : "; Timer - D; " 秒" Print "請按任何鍵繼續" B = False End If Else Randomize S1 = "" Cls '前景色改成紅色 ForeColor = 255 '隨機看要出幾個字(5~10之間) N = Int(Rnd * 6 + 5) For I = 1 To N Do '隨機從S字串中取字 X = Int(Rnd * Len(S) + 1) '以InStr判斷取得的字跟S1字串中的字是否有重複,有的話重選,否則就離開Do~Loop Loop Until InStr(S1, Mid(S, X, 1)) = 0 '把選出來的字加入S1 S1 = S1 & Mid(S, X, 1) '輸出 Print Mid(S, X, 1); " "; Next Print '前景色改成黑色 ForeColor = 0 B = True '計時開始 D = Timer End IfEnd SubPrivate Sub Form_Load() Dim I As Integer '表單參數設定 AutoRedraw = True FontName = "Times New Roman" FontSize = 14 FontBold = True KeyPreview = True 'S=A~Z,若只要數字可把S="0123456789",再把底下的For~Next刪除 For I = 65 To 90 S = S & Chr(I) Next Print "請按任何鍵開始"End Sub
2006-06-11 10:23:13 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋