自己平常有興趣偶爾寫寫的小程式
若有寫的不好地方還請見諒啦

Option Explicit

Public dblRunNum As Double '記錄產生的數字
Public dblPerNum As Double '記錄前方索引數字
Public dblBackNum As Double '記錄後方索引數字
Private Sub Command1_Click()
    Call check_data
End Sub

Private Sub Command3_Click()
    txtAns.Visible = True
End Sub

Private Sub Form_Load()
    dblPerNum = 1
    dblBackNum = 100
    lblMessage.Caption = "請輸入" & dblPerNum & "到" & dblBackNum & "的數字"
    Call roundNum
End Sub

Public Sub roundNum()
    Randomize
    dblRunNum = Int(Rnd() * 100) + 1
    txtAns.Text = dblRunNum
    txtAns.Visible = False
End Sub

Private Sub Command2_Click()
    Call roundNum
End Sub

Private Sub check_data()
    If Not IsNumeric(GuestNum.Text) Then
        MsgBox "必需輸入數字", vbInformation + vbOKOnly, "檢查"
        lblMessage.Caption = "必需輸入數字"
    Else
        Dim dblInputNum As Double
        dblInputNum = GuestNum.Text
        If Not (dblPerNum < dblInputNum And dblInputNum < dblBackNum) Then
            MsgBox "請輸入" & dblPerNum & "到" & dblBackNum & "的數字", vbInformation + vbOKOnly, "檢查"
        ElseIf dblRunNum = dblInputNum Then
            lblMessage.Caption = "接受處罰~~"
        ElseIf dblRunNum > dblInputNum Then
            lblMessage.Caption = " " & dblInputNum & " ~ " & dblBackNum & " "
           dblPerNum = dblInputNum
        ElseIf dblRunNum < dblInputNum Then
            lblMessage.Caption = " " & dblPerNum & " ~ " & dblInputNum & " "
            dblBackNum = dblInputNum
        Else
             MsgBox "必需輸入數字", vbInformation + vbOKOnly, "檢查"
        End If
    End If
    GuestNum.SetFocus
    GuestNum.SelStart = 0
    GuestNum.SelLength = Len(GuestNum.Text)
End Sub

Private Sub GuestNum_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        Call check_data
    End If
End Sub

下載範例: VB6 終極密碼

創作者介紹

歡迎~ 程式設計 學生 作業 專題製作 程式外包 家教...

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