Tony041010

計算突刺個數並畫出結構

Jul 14th, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim p As Integer '第四題用來記錄游標在text2中的位置
  2. Private Sub Command1_Click()
  3.     '第一題,計算刺突個數
  4.    a = Split(Text2, Text1)
  5.     Label3 = UBound(a)
  6. End Sub
  7.  
  8. Private Sub Command2_Click()
  9.     Command1_Click
  10.     '第二題,畫出刺突,簡化為2D
  11.    Me.Cls  '清除form上面的所有作畫
  12.    Me.DrawWidth = 2
  13.     X1 = (Image1.Left + Image1.Width / 2)
  14.     Y1 = (Image1.Top + Image1.Height / 2)
  15.     Me.Circle (X1, Y1), 2000, vbRed
  16.    
  17.  Me.DrawWidth = 6
  18.  For i = 1 To Label3
  19.     X1 = (Image1.Left + Image1.Width / 2) + 2000 * Cos(i / Label3 * 2 * 3.14)
  20.     Y1 = (Image1.Top + Image1.Height / 2) + 2000 * Sin(i / Label3 * 2 * 3.14)
  21.    
  22.     X2 = (Image1.Left + Image1.Width / 2) + 2300 * Cos(i / Label3 * 2 * 3.14)
  23.     Y2 = (Image1.Top + Image1.Height / 2) + 2300 * Sin(i / Label3 * 2 * 3.14)
  24.    
  25.     Line (X1, Y1)-(X2, Y2), vbRed
  26.     Me.Circle (X2, Y2), 200, vbRed
  27.     Me.FontSize = 16
  28.     Print i
  29.  Next
  30.  
  31.  
  32. End Sub
  33.  
  34. Private Sub Command3_Click()
  35.     Command1_Click
  36.     '第三題,畫出刺突,簡化為2D,中間畫3個
  37.    Me.Cls  '清除form上面的所有作畫
  38.    Me.DrawWidth = 2
  39.     X1 = (Image1.Left + Image1.Width / 2)
  40.     Y1 = (Image1.Top + Image1.Height / 2)
  41.     Me.Circle (X1, Y1), 2000, vbRed
  42.    
  43.     Me.DrawWidth = 6
  44.     For i = 1 To 3
  45.         X2 = (Image1.Left + Image1.Width / 2) + 1000 * Cos(i / 3 * 2 * 3.14)
  46.         Y2 = (Image1.Top + Image1.Height / 2) + 1000 * Sin(i / 3 * 2 * 3.14)
  47.        
  48.         Me.Circle (X2, Y2), 200, vbRed
  49.        
  50.         Me.FontSize = 16
  51.         Print i
  52.     Next
  53.     For i = 1 To Label3 - 3
  54.         X1 = (Image1.Left + Image1.Width / 2) + 2000 * Cos(i / (Label3 - 3) * 2 * 3.14)
  55.         Y1 = (Image1.Top + Image1.Height / 2) + 2000 * Sin(i / (Label3 - 3) * 2 * 3.14)
  56.        
  57.         X2 = (Image1.Left + Image1.Width / 2) + 2300 * Cos(i / (Label3 - 3) * 2 * 3.14)
  58.         Y2 = (Image1.Top + Image1.Height / 2) + 2300 * Sin(i / (Label3 - 3) * 2 * 3.14)
  59.        
  60.         Line (X1, Y1)-(X2, Y2), vbRed
  61.         Me.Circle (X2, Y2), 200, vbRed
  62.         Me.FontSize = 16
  63.         Print i + 3
  64.     Next
  65. End Sub
  66.  
  67. '第四題,搜尋並反白
  68. Private Sub Command4_Click()
  69.     Text2.SetFocus
  70.     p = InStr(p, Text2, Text1)
  71.     Print p
  72.     If p = 0 Then
  73.         Print "not found"
  74.         p = 1
  75.     Else
  76.         Text2.SelStart = p - 1
  77.         Text2.SelLength = Len(Text1)
  78.         p = p + 1
  79.     End If
  80. End Sub
  81.  
  82. Private Sub Form_Load()
  83.     p = 1
  84. End Sub
  85.  
Add Comment
Please, Sign In to add comment