Tony041010

絕地救援 : 16進位

Jul 14th, 2021 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '第1題
  2. Private Sub Command1_Click()
  3.     Text2.Text = ""
  4.     For i = 1 To Len(Text1.Text)
  5.         Text2.Text = Text2.Text & Hex(Asc(Mid(Text1, i, 1)))
  6.     Next
  7. End Sub
  8.  
  9. '第2題
  10. Private Sub Command2_Click()
  11.     Text3.Text = ""
  12.     'step 2表示一次取兩位,因為16進位組合成字元,每次都是2位為一組,比如a為61(hex)
  13.    For i = 1 To Len(Text2.Text) Step 2
  14.         Text3.Text = Text3.Text & Chr(Val("&H" & Mid(Text2, i, 2)))
  15.     Next
  16.  
  17. End Sub
  18.  
  19. '第3題,第4題
  20. Private Sub Timer1_Timer()
  21.     '第三題,時鐘每滴答一次,取一個十六進位數字,轉成十進位後丟到sincos繪圖。
  22.    '為什麼不用FOR迴圈取每個數字並繪圖,其實也是可以,但FOR迴圈太快了,你無法看到每個數字轉動的效果。
  23.    Me.Cls  '清除form上面的所有作畫
  24.    '繪製圓心與刻度16進位
  25.    x = (Image1.Left + Image1.Width / 2)
  26.     y = (Image1.Top + Image1.Height / 2)
  27.    
  28.     Me.DrawWidth = 1
  29.     Me.Circle (x, y), 2000
  30.     For i = 0 To 15
  31.         Me.CurrentX = x + Cos(i * 2 / 16 * 3.14) * 2300
  32.         Me.CurrentY = y + Sin(i * 2 / 16 * 3.14) * 2300
  33.         Me.Print Hex(i)
  34.     Next
  35.    
  36.    
  37.     '第三題
  38.    
  39.     '計算位置與取字
  40.    'Label1 = (Label1 + 1)  '每次進一位
  41.    
  42.     'If Label1 <= Len(Text2) Then
  43.        'a = Val("&H" & Mid(Text2.Text, Label1, 1))
  44.    'Else
  45.        'Timer1.Interval = 0
  46.    'End If
  47.    
  48.     '開始繪圖
  49.    'x = (Image1.Left + Image1.Width / 2) + 2000 * Cos(a * 2 / 16 * 3.14) 'cos(n),n的值由0-2PI
  50.   ' y = (Image1.Top + Image1.Height / 2) + 2000 * Sin(a * 2 / 16 * 3.14)
  51.    'Me.Circle (x, y), 200, vbRed
  52.    '畫線
  53.   ' Line ((Image1.Left + Image1.Width / 2), (Image1.Top + Image1.Height / 2))-(x, y), vbRed
  54.    
  55.     '第四題
  56.    If Label1 <= Len(Text2.Text) Then
  57.         If Label2 = Label3 Then
  58.             Timer1.Interval = 1000
  59.             Label1 = (Label1 + 1)
  60.             Label2 = Val("&H" & Mid(Text2, Label1, 1)) 'Label2為當前的數字
  61.            Label3 = Val("&H" & Mid(Text2, Label1 + 1, 1)) ' Label3為目標
  62.            If Label3 > Label2 Then
  63.                 If Label3 - Label2 < 8 Then
  64.                     Label4 = 1
  65.                 Else
  66.                     Label4 = -1
  67.                 End If
  68.             ElseIf Label3 < Label2 Then
  69.                 If Label2 - Label3 < 8 Then
  70.                     Label4 = -1
  71.                 Else
  72.                     Label4 = 1
  73.                 End If
  74.             Else
  75.                 Label4 = 0
  76.             End If
  77.             x = (Image1.Left + Image1.Width / 2) + 2000 * Cos(Label2 * 2 / 16 * 3.14)
  78.             y = (Image1.Top + Image1.Height / 2) + 2000 * Sin(Label2 * 2 / 16 * 3.14)
  79.             Me.DrawWidth = 8
  80.             Line ((Image1.Left + Image1.Width / 2), (Image1.Top + Image1.Height / 2))-(x, y), vbRed
  81.             Me.Circle (x, y), 200, vbRed
  82.         Else
  83.             Me.DrawWidth = 3
  84.             Timer1.Interval = 500
  85.             Label2 = (Val(Label2) + Label4 + 16) Mod 16
  86.             x = (Image1.Left + Image1.Width / 2) + 2000 * Cos(Label2 * 2 / 16 * 3.14)
  87.             y = (Image1.Top + Image1.Height / 2) + 2000 * Sin(Label2 * 2 / 16 * 3.14)
  88.              Line ((Image1.Left + Image1.Width / 2), (Image1.Top + Image1.Height / 2))-(x, y), vbBlack
  89.              
  90.         End If
  91.     Else
  92.     Timer1.Interval = 0
  93.     End If
  94.    
  95.    
  96.  
  97. End Sub
  98. Private Sub Command3_Click()
  99.     '第三題,開啟時鐘與繪圖
  100.    Timer1.Interval = 1000
  101.     Label1 = 0
  102.     Me.Cls  '清除form上面的所有作畫
  103.    '繪製圓心與刻度16進位
  104.    x = (Image1.Left + Image1.Width / 2)
  105.     y = (Image1.Top + Image1.Height / 2)
  106.    
  107.     Me.Circle (x, y), 2000
  108.     For i = 0 To 15
  109.         Me.CurrentX = x + Cos(i * 2 / 16 * 3.14) * 2300
  110.         Me.CurrentY = y + Sin(i * 2 / 16 * 3.14) * 2300
  111.         Me.Print Hex(i)
  112.     Next
  113. End Sub
  114.  
Add Comment
Please, Sign In to add comment