---
# System prepended metadata

title: VB6上課記錄2019.1.30
tags: [' dp107', vb6教學, ' dp1072']

---

---
title: VB6上課記錄2019.1.30
description: 彰商資處科107學年度程設
image:
tags: vb6教學, dp107, dp1072
robots: noindex, nofollow
GA:
---

VB6上課記錄2019.1.30
===

![](https://i.imgur.com/g13UARY.jpg)




# 感想 
覺得小時鐘特別難 :hatched_chick: 

# 程式碼


賽車
```vba=
Private Sub cmdGo_Click()
    If Me.cmdGo.Caption = "走" Then
        
        Me.Timer1.Enabled = Not Me.Timer1.Enabled
    
    End If
    
    If Me.cmdGo.Caption = "重來" Then
    
        Call 回復原位
        
        Me.cmdGo.Caption = "走"
    End If
    
End Sub

Sub 回復原位()
    
    
    For i = Me.img車.LBound To Me.img車.UBound
    
    
        Me.img車(i).Left = Me.ln起始.X1 - Me.img車(i).Width
        
        Me.lbl名次(i).Caption = "0"
        Me.lbl名次(i).Visible = False
        o名次 = 0
        Me.img車(i).Tag = ""
    Next
    
    
End Sub

Private Sub Timer1_Timer()
    
    For i = Me.img車.LBound To Me.img車.UBound
    
        If Me.img車(i).Tag <> "到了" Then
            
            
           Me.img車(i).Left = Me.img車(i).Left + Int(Rnd * 151) + 50
         
            
           If Me.img車(i).Left + Me.img車(i).Width >= Me.ln終點.X1 Then
                
                Me.img車(i).Tag = "到了"
                
                o名次 = o名次 + 1
                
                Me.lbl名次(i).Caption = o名次
                
                Me.lbl名次(i).Visible = True
                
            End If
            
        End If
        
    
    Next
    
         If o名次 = Me.img車.Count Then
                
                Me.cmdGo.Caption = "重來"
                
               
            Me.Timer1.Enabled = Not Me.Timer1.Enabled
        End If
End Sub

```

清單
```vba=
Private Sub cmd加入_Click()
    
    If Me.txt項目 <> "" Then
    
        Me.lst清單1.AddItem Me.txt項目.Text
        Me.txt項目.Text = ""
        
    Else
    
        MsgBox "請輸入文字", , "警告"
    
    End If
    
    
    Me.txt項目.SetFocus
End Sub

Private Sub cmd插入_Click()
    
    i = Me.lst清單1.ListIndex
    x = Me.txt項目.Text
    If Me.lst清單1.ListIndex = -1 Then
    
        Me.lst清單1.AddItem x, 0
     Else
     
        Me.lst清單1.AddItem x, i
    End If
    
        Me.txt項目.Text = ""
End Sub

Private Sub cmd刪除_Click()
    
    i = Me.lst清單1.ListIndex
    
    
    If Me.lst清單1.ListIndex = -1 Then
   
        Me.lst清單1.RemoveItem 0
        
    Else
    
        Me.lst清單1.RemoveItem i
        
    End If
        
    

End Sub

Private Sub cmd清空_Click()
    '
    
    Me.lst清單1.Clear
    
End Sub

Private Sub cmd往右_Click()
    '
    
End Sub

Private Sub cmd往左_Click()
    '

End Sub

Private Sub cmd全往右_Click()
    '
    
End Sub

Private Sub cmd全往左_Click()
    '
    
End Sub

Private Sub lst清單1_DblClick()
    '
    
End Sub

Private Sub lst清單2_DblClick()
    '
    
End Sub

Private Sub txt項目_KeyPress(KeyAscii As Integer)
    'KeyAscii=13表示<Enter>鍵,自動幫按「加入」鈕
    
    If KeyAscii = 13 Then
    
        Call cmd加入_Click
        
    End If
    
End Sub

```

小精靈
```vba=
Dim r半徑 As Integer
Dim o方向 As Integer
Dim x As Integer
Dim y As Integer
Dim o數值 As Integer

Function D2PI(d)

    D2PI = d / 180 * 3.14159
    
End Function
Private Sub cmd方向_Click(Index As Integer)
    
    o方向 = Index
    
    Me.Timer1.Enabled = True
    
End Sub

Private Sub Form_Load()
     
    o數值 = 100
     
    r半徑 = 1000
    x = Me.ScaleWidth / 2
    y = Me.ScaleHeight / 2
    
    Me.Show
    
    
    o方向 = 3
    Me.Circle (x, y), r半徑, , -D2PI(45), -D2PI(315)
    
    Me.Timer1.Enabled = False
    
End Sub

Private Sub Timer1_Timer()
    

       
        
    Me.Cls
    Select Case o方向
        
        
        Case 0
            y = y - 100
            Me.Circle (x, y), r半徑, , -D2PI(135), -D2PI(45)
                                
             If y < 0 + r半徑 Then
             
                y = 0 + r半徑
            End If
                
        Case 1
            y = y + 100
             Me.Circle (x, y), r半徑, , -D2PI(315), -D2PI(225)
            
            If y > Me.ScaleHeight - r半徑 Then
            
                y = Me.ScaleHeight - r半徑
            
            End If
            
        Case 2
            x = x - 100
             Me.Circle (x, y), r半徑, , -D2PI(225), -D2PI(135)
            
            If x < 0 + r半徑 Then
            
                x = r半徑
            End If
            
        Case 3
            
            x = x + 100
            
            Me.Circle (x, y), r半徑, , -D2PI(45), -D2PI(315)
            
            If x > Me.ScaleWidth - r半徑 Then
            
                x = Me.ScaleWidth - r半徑
            End If
```

畫時鐘
```vba=
Dim rr As Single '半徑

Private Sub Form_Load()

    rr = 3 / 4 * (Me.pic.ScaleWidth / 2)  '最大的那一個圖的半徑=3/4半寬度
    
    '在form_load時，form還沒有出現
    Me.Show     '強迫自己show出來，才可以畫圖
    
    Call 畫時鐘
    Call Timer1_Timer
End Sub

Private Sub 畫時鐘()
    
    '用麥克筆畫
    Me.pic.AutoRedraw = True
        
    '畫外框(圓1)
    
    Me.pic.DrawWidth = 7
    Me.pic.FillStyle = 0
    Me.pic.FillColor = RGB(255, 135, 135)
    Me.pic.ForeColor = RGB(255, 100, 100)
    r = rr
    Me.pic.Circle (0, 0), r
    
    '畫外框(圓2)
    '填滿實心
    '填滿的顏色
    '筆畫粗細
    '畫筆的顏色(前景)
    '半徑
    '畫出來
    
    Me.pic.FillStyle = 0
    Me.pic.DrawWidth = 5
    Me.pic.FillColor = RGB(155, 135, 135)
    Me.pic.ForeColor = RGB(155, 100, 100)
    r = rr - 50
    Me.pic.Circle (0, 0), r
    
    '畫點(分)

    Me.pic.DrawWidth = 2
    r = rr - 55
    For i = 0 To 354 Step 6
    
        x = r * Cos(D2PI(i + 90))
        y = r * Sin(D2PI(i + 90))
        Me.pic.PSet (x, y), vbBlack
        
    Next
    


    '畫點(時)
    Me.pic.DrawWidth = 4
    r = rr - 55
    For i = 0 To 330 Step 30
    
        x = r * Cos(D2PI(i + 90))
        y = r * Sin(D2PI(i + 90))
        Me.pic.PSet (x, y), vbBlack
        
    Next
    
    
    '畫圖心

    Me.pic.PSet (0, 0), vbBlack
    
    '改用粉筆畫
    Me.pic.AutoRedraw = False
End Sub

Function D2PI(d)
    '
    D2PI = d / 180 * 3.14159
    
End Function

Private Sub pic_Click()

End Sub

Private Sub Timer1_Timer()
    
    h = Hour(Now()) Mod 12                   '時
    m = Minute(Now())                    '分
    s = Second(Now())                   '秒
    
    '清畫面
    Me.pic.Cls
    
    '設畫筆顏色
    pic.ForeColor = RGB(50, 50, 50)
    
    '畫現在時間 (幫你寫好了，送分，不過你在上面要把h m s先算出來)
    pic.CurrentX = -80
    pic.CurrentY = -200
    pic.Print h & ":" & m & ":" & s
    
    
    '畫秒針
    r = rr - 70
    
    Me.pic.DrawWidth = 1
    sita = 360 - 6 * s + 90
    x = r * Cos(D2PI(sita))
    y = r * Sin(D2PI(sita))
    Me.pic.Line (0, 0)-(x, y), vbRed
    
    
    '畫分針
    r = rr - 90

     Me.pic.DrawWidth = 2
    sita = 360 - 6 * m + 90
    x = r * Cos(D2PI(sita))
    y = r * Sin(D2PI(sita))
    Me.pic.Line (0, 0)-(x, y), vbBlue

    '畫時針
    r = rr - 120
    
    
     Me.pic.DrawWidth = 2
    sita = 360 - 6 * h + 90 - (1 / 2 * m)
    x = r * Cos(D2PI(sita))
    y = r * Sin(D2PI(sita))
    Me.pic.Line (0, 0)-(x, y), vbBlack
    
End Sub

```

```vba=
Private Sub Form_Load()

End Sub

Private Sub img小時鐘_Click()
    '
    
    frm小時鐘.Show
    
End Sub

Private Sub img小精靈_Click()
    '
    frm小精靈.Show
    
End sub
Private Sub img清單_Click()
    '
    frm清單綜合操作.Show
    
End Sub

Private Sub img賽車_Click()
    '
    frm賽車.Show

End Sub
```

# 影片
https://drive.google.com/drive/folders/1ft_dBO0v5lqpxAyfwlOmH7wsrvdxxeb9