小小计算机程式码参考.DOC

小小计算机程式码参考

VB基礎程式 1.各種面積計算程式碼參考: Private Sub Command1_Click() 三角形面積 Dim Area, 底, 高 As Double 底 = InputBox(請輸入三角形的底(公分):) 高 = InputBox(請輸入三角形的高(公分):) Area = Tri_Area(底, 高) MsgBox 三角形面積是: Area 平方公分 End Sub Function Tri_Area(ByVal a1, ByVal a2) As Double Tri_Area = a1 * a2 / 2 End Function Private Sub Command2_Click() 梯形面積 Dim Area, 上底, 下底, 高 As Double 上底 = Val(InputBox(請輸入梯形的上底(公分):)) 下底 = Val(InputBox(請輸入梯形的下底(公分):)) 高 = InputBox(請輸入梯形的高(公分):) Area = Four_Area(上底, 下底, 高) MsgBox 梯形面積是: Area End Sub Function Four_Area(ByVal a1, ByVal a2, ByVal a3) As Double Four_Area = (a1 + a2) * a3 / 2 End Function Private Sub Command3_Click() 圓形面積 Dim Area, r As Double r = InputBox(請輸入圓形的半徑(公分):) Area = Round_Area(r) MsgBox 圓形面積是: Area End Sub Function Round_Area(ByVal a1) As Double Round_Area = 3.14 * a1 ^ 2 End Function Private Sub Command4_Click() 長方形面積 Dim Area, 長, 寬 As Double 長 = InputBox(請輸入長方形的長(公分):) 寬 = InputBox(請輸入長方形的寬(公分):) Area = Long_Area(長, 寬) MsgBox 長方形面積是: Area End Sub Function Long_Area(ByVal a1, ByVal a2) As Double Long_Area = a1 * a2 End Function Private Sub Command5_Click() 正方形面積 Dim Area, 長 As Double 長 = InputBox(請輸入正方形的長(公分):) Area = short_Area(長) MsgBox 正方形面積是: Area End Sub Function short_Area(ByVal a1) As Double short_Area = a1 * a1 End Function Private Sub Command6_Click() 結束 End End Sub 2.溫度轉換程式碼參考: Private Sub Command1_Click() F = InputBox(請輸入華氏溫度, 溫度轉換) C = (F - 32) * 5 / 9 Label1 = 輸入華氏溫度 F 度後 轉成攝氏溫度為 C 度 End Sub Private Sub Command2_Click() C = InputBox(請輸入攝氏溫度, 溫度轉換) F = 9 / 5 * C + 32 Label1 = 輸入華氏溫度 C 度後 轉成攝氏溫度為 F 度 End Sub 3.小小計算機程式碼參考: Private Sub Command1_Click() a = Val(Text1.Text) b = Val(Text2.Text) Label1 = + Label2 = = Label3 = a + b End Sub Private Sub Command2_Click() a = Val(Text1.Text) b = Val(Text2.Text) Label1 = - Label2 = = Label3 = a - b End Sub Private Sub Command3_Click() a = Val(Text1.Text) b = Val(Text2.Text) Label1 = * Label2 = = Label3 = a * b End Sub Private Sub

文档评论(0)

1亿VIP精品文档

相关文档