VisualBasic程序設(shè)計教程曹青邱李華等編著機(jī)械工業(yè)出版社答案.doc

上傳人:good****022 文檔編號:116529968 上傳時間:2022-07-05 格式:DOC 頁數(shù):15 大?。?33KB
收藏 版權(quán)申訴 舉報 下載
VisualBasic程序設(shè)計教程曹青邱李華等編著機(jī)械工業(yè)出版社答案.doc_第1頁
第1頁 / 共15頁
VisualBasic程序設(shè)計教程曹青邱李華等編著機(jī)械工業(yè)出版社答案.doc_第2頁
第2頁 / 共15頁
VisualBasic程序設(shè)計教程曹青邱李華等編著機(jī)械工業(yè)出版社答案.doc_第3頁
第3頁 / 共15頁

下載文檔到電腦,查找使用更方便

10 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《VisualBasic程序設(shè)計教程曹青邱李華等編著機(jī)械工業(yè)出版社答案.doc》由會員分享,可在線閱讀,更多相關(guān)《VisualBasic程序設(shè)計教程曹青邱李華等編著機(jī)械工業(yè)出版社答案.doc(15頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、家電維修社團(tuán)整理- 15 -P37#2-4Private Sub cmdBegin_Click() Timer1.Enabled = True 激活定時器 cmdBegin.Enabled = False cmdEnd.Enabled = TrueEnd SubPrivate Sub cmdEnd_Click() Timer1.Enabled = False 關(guān)閉定時器 Label1.Left = 0 標(biāo)簽歸位到窗體左側(cè) cmdBegin.Enabled = True cmdEnd.Enabled = FalseEnd SubPrivate Sub Form_Load() Label1.Lef

2、t = 0 初始將標(biāo)簽歸位到窗體左側(cè)End SubPrivate Sub Timer1_Timer() Label1.Move Label1.Left + 20 每隔0.1秒標(biāo)簽向右移動20緹End Sub2-5Dim tmpPrivate Sub Command1_Click() “復(fù)制”按鈕 Text1.SetFocus 焦點定位在文本框Text1 tmp = Text1.SelText 將選中的內(nèi)容存放在變量tmp中End SubPrivate Sub Command2_Click() “剪切”按鈕 tmp = Text1.SelText 將選中的內(nèi)容存放在變量tmp中 Text1.Se

3、lText = 將選中的內(nèi)容置為空串 Text1.SetFocus 焦點定位在文本框Text1End SubPrivate Sub Command3_Click() “粘貼”按鈕 Text1.SelText = tmp 將變量tmp的值賦給文本框選中的內(nèi)容 Text1.SetFocus 焦點定位在文本框Text1End SubPrivate Sub Command4_Click() “下劃線”按鈕 Text1.FontUnderline = Not Text1.FontUnderline 設(shè)置或取消下劃線End SubPrivate Sub Command5_Click() “刪除線”按鈕 T

4、ext1.FontStrikethru = Not Text1.FontStrikethru 設(shè)置或取消刪除線End SubPrivate Sub Command6_Click() “加粗”按鈕 Text1.FontBold = Not Text1.FontBold 設(shè)置或取消加粗線End SubPrivate Sub Command7_Click() “傾斜”按鈕 Text1.FontItalic = Not Text1.FontItalic 設(shè)置或取消傾斜End SubPrivate Sub Command8_Click() “放大”按鈕 Text1.FontSize = Text1.Fo

5、ntSize + 5 字體放大5磅End SubPrivate Sub Command9_Click() “縮小”按鈕 Text1.FontSize = Text1.FontSize - 5 字體縮小5磅End SubP38#2-8Private Sub Form_Load() 在開始運行時設(shè)置各文本框的文字大小和字體 Text2.FontName = 隸書 Text2.FontSize = 16 Text3.FontName = 楷體_GB2312 Text3.FontSize = 18End SubPrivate Sub Text1_Change() 在Text1中改變內(nèi)容時改變Text2

6、和Text3的內(nèi)容 Text2.Text = Text1.Text Text3.Text = Text1.TextEnd SubPrivate Sub Command1_Click() 清除按鈕 Text1.Text = End SubPrivate Sub Command2_Click() 退出按鈕 EndEnd Sub2-9Private Sub Command1_Click()Command1.Visible = FalseCommand2.Visible = TrueLabel1.BorderStyle = 1End SubPrivate Sub Command2_Click()Com

7、mand1.Visible = TrueCommand2.Visible = FalseLabel1.BorderStyle = 0End SubPrivate Sub Command3_Click()Command3.Visible = FalseCommand4.Visible = TrueLabel1.BackStyle = 1End SubPrivate Sub Command4_Click()Command3.Visible = TrueCommand4.Visible = FalseLabel1.BackStyle = 0End SubP60/613-1Private Sub Co

8、mmand1_Click() Const pi = 3.1415926535898 Dim h As Single Dim r As Single h = Val(Text1.Text) r = Val(Text2.Text) Text3.Text = Format(pi * r 2, 0.000) Text4.Text = Format(2 * pi * r * h, 0.000) Text5.Text = Format(pi * r 2 * h, 0.000)End Sub3-2Private Sub Command1_Click() Randomize Text1.Text = Int(

9、Rnd * 100 + 1) Text2.Text = Int(Rnd * 100 + 1) Text3.Text = End SubPrivate Sub Command2_Click() Text3.Text = Val(Text1.Text) + Val(Text2.Text)End Sub3-4Private Sub Timer1_Timer() y = Year(Date) 求當(dāng)前日期的年份 mon = Month(Date) 求當(dāng)前日期的月份 d = Day(Date) 求當(dāng)前日期是月份中的第幾天 Label1.Caption = y & 年 & mon & 月 & d & 日 將

10、年、月、日串接起來 h = Hour(Time) 求當(dāng)前時間的小時部分 Min = Minute(Time) 求當(dāng)前時間的分鐘部分 s = Second(Time) 求當(dāng)前時間的秒部分 Label2.Caption = h & 時 & Min & 分 & s & 秒 將時、分、秒串接起來End SubP684-4Option ExplicitPrivate Sub Command1_Click() Dim A As Single, B As Single, C As Single Dim P As Single, S As Single A = Val(Text1.Text) B = Val(

11、Text2.Text) C = Val(Text3.Text) P = (A + B + C) / 2 S = Sqr(P * (P - A) * (P - B) * (P - C) Label2.Caption = Format(Str(S), 0.00) 顯示時保留兩位小數(shù)End SubP76#4-1Private Sub Command1_Click() ZJ.Text = Val(DJ.Text) * Val(SL.Text)End SubPrivate Sub Command2_Click() EndEnd Sub4-3Private Sub Command1_Click() X =

12、 Val(Text1.Text) X1 = X * 3.1416 / 180 SX = Abs(Sin(X1) CX = Abs(Cos(X1) Text2.Text = Text2.Text & _ Format(X, 0.000) & & _ Format(SX, 0.000) & & _ Format(CX, 0.000) & Chr(13) & Chr(10) Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text)End Sub4-4Private Sub Form_Click() h = Val(Inpu

13、tBox(請輸入小時, 將時間轉(zhuǎn)換成秒, 0) m = Val(InputBox(請輸入分, 將時間轉(zhuǎn)換成秒, 0) s = Val(InputBox(請輸入秒, 將時間轉(zhuǎn)換成秒, 0) Total = h * 3600 + m * 60 + s Print h; 小時; m; 分; s; 秒=; Total; 秒End SubP895-5Private Sub Text1_Change() Label2.Caption = End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)Static I As Integ

14、er 變量I統(tǒng)計輸入錯誤口令的次數(shù)If KeyCode = 13 Then 如果按下的鍵為回車鍵 If UCase(Text1.Text) = HELLO Then 如果口令為HELLO Label2.Caption = 恭喜!,您已成功進(jìn)入本系統(tǒng) ElseIf I = 0 Or I = 1 Then 如果口令錯且錯誤次數(shù)少于2 I = I + 1 Label2.Caption = 口令錯!,請重新輸入 Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Else 如果口令錯且錯誤次數(shù)等于2 MsgBox 對不起,您不能使用本系統(tǒng) End

15、退出應(yīng)用程序。 End IfEnd IfEnd SubP92#5-1Private Sub Command1_Click() x = Val(Text1.Text) If x Mod 3 = 0 And x Mod 5 = 0 And x Mod 7 = 0 Then Text2.Text = 能同時被3、5、7整除 Else Text2.Text = 不能整除End Sub5-2Private Sub Form_Load()Dim x As Single, y As Single, z As Single, max As Single, min As Singlex = InputBox(第

16、一個)y = InputBox(第二個)z = InputBox(第三個)If x y Then max = xElse: max = yEnd IfIf max z Then max = zw = MsgBox( 最大值 & max)End IfIf x z Then min = zw = MsgBox( 最小值 & min)End IfText1.Text = maxText2.Text = minEnd Sub5-6Private Sub Command1_Click() x = Val(Text1.Text) Select Case x Case Is 100 Label2.Capti

17、on = MsgBox 輸入的數(shù)據(jù)超出范圍,請重新輸入 Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Case Is = 90 Label2.Caption = 優(yōu) Case Is = 80 Label2.Caption = 良 Case Is = 70 Label2.Caption = 中 Case Is = 60 Label2.Caption = 及格 Case Else Label2.Caption = 不及格 End SelectEnd Sub5-7Dim I As IntegerPrivate

18、Sub Command1_Click() kl = UCase(Trim(Text1.Text) If kl = ABCD Then I = 0 Form2.Show Else If I = 2 Then MsgBox 對不起,您不能使用本系統(tǒng) End Else Form1.Caption = 口令錯,請重新輸入 I = I + 1 Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End IfEnd SubPrivate Sub Text1_Change() Form1.Caption = 口

19、令檢測End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then kl = UCase(Trim(Text1.Text) If kl = ABCD Then I = 0 Form2.Show Else If I = 2 Then MsgBox 對不起,您不能使用本系統(tǒng) End Else Form1.Caption = 口令錯,請重新輸入 I = I + 1 Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If

20、End If End IfEnd SubP96#6-2Private Sub Form_Click() A = 1 B = 1 Text1.Text = Str(A) & Str(B) & Chr(13) & Chr(10) For I = 1 To 9 A = A + B B = A + B Text1.Text = Text1.Text & Str(A) & Str(B) & Chr(13) & Chr(10) Next IEnd SubP101#6-6A*Private Sub Picture1_Click() For I = 1 To 9 For J = 1 To 9 Picture1

21、.Print Format(I); ; Format(J); =; Format(I * J, !); Next J Picture1.Print Next IEnd SubB*Private Sub Picture1_Click() For I = 1 To 9 For J = 1 To I Picture1.Print Format(I); ; Format(J); =; Format(I * J, !); Next J Picture1.Print Next IEnd SubP106#6-11Dim N As IntegerPrivate Sub Command1_Click() “求最

22、大公約數(shù)”按鈕的事件過程 M = Val(Text1.Text): N = Val(Text2.Text) 輸入M,N A = M: B = N 將M、N暫時保存在變量A、B中,用于求最小公倍數(shù) R = M Mod N 求M除以N的余數(shù)R Do While R 0 當(dāng)余數(shù)R不為0時執(zhí)行循環(huán)體 M = N 將除數(shù)N做為新的被除數(shù)M N = R 將余數(shù)R做為新的除數(shù)N R = M Mod N 求M除以N的余數(shù)R Loop Label3.Caption = N 輸出最大公約數(shù)N Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click() 求最

23、小公倍數(shù)按鈕的事件過程 Label4.Caption = Val(Text1.Text) * Val(Text2.Text) / NEnd Sub6-12Private Sub Command1_Click() N = Val(Text1.Text): K = Int(Sqr(N): I = 2 Do While I = K If N Mod I 0 Then I = I + 1 不能整除,ID的值累加1 Else Exit Do 整除,退出循環(huán) End If Loop If I = K Then Label2.Caption = 不是素數(shù) Else Label2.Caption = 是素數(shù)

24、End IfEnd SubPrivate Sub Text1_Change() Label2.Caption = End SubP1136-1Private Sub Command1_Click() s1 = 0 For k = 1 To 100 s1 = s1 + k Next k s2 = 0 For k = 1 To 50 s2 = s2 + k 2 Next k s3 = 0 For k = 1 To 10 s3 = s3 + 1 / k Next k Label1.Caption = Format(s1 + s2 + s3, 0.0000)End Sub6-2Private Sub

25、Command1_Click() s = 0 n = Val(Text1.Text) k = 2 For i = 1 To 2 * n - 1 Step 2 s = s + (-1) k * 1 / i k = k + 1 Next i s = 4 * s Text2.Text = Format(s, 0.0000)End Sub6-3Private Sub Command1_Click() a = Val(InputBox(請輸入A) n = Val(InputBox(請輸入N) Sum = 0 Item = 0 For j = 1 To n Item = Item * 10 + a Sum

26、 = Sum + Item Next j Text1.Text = SumEnd Sub6-4Private Sub Form_Click() a = 2 b = 1 s = 0 For i = 1 To 20 s = s + a / b c = a a = a + b b = c Next i MsgBox 和為: & sEnd Sub6-5Private Sub Command1_Click() n = Val(Text1.Text) f = 1 For i = 1 To n f = f * (2 * i - 1) Next i Label2.Caption = fEnd Sub6-6Pr

27、ivate Sub Command1_Click() For i = 3 To 100 Step 2 Text1.Text = Text1.Text & Str(i) & vbCrLf Next iEnd Sub6-9Private Sub Command1_Click()f = 1i = 1Do While f = 400000 f = f * i i = i + 2LoopText1.Text = fEnd Sub6-10Private Sub Command1_Click()m = 0n = 0Do While n 0 num1 = num1 + 1 sum1 = sum1 + A(i)

28、 Case Is Max Then Max = a(i) End If Next i Text2.Text = MaxEnd Sub7-5Dim A(1 To 20) As IntegerPrivate Sub Command1_Click() Text1.Text = Randomize For i = 1 To 20 A(i) = Int(Rnd * 50 + 1) Text1.Text = Text1.Text & Str(A(i) & Space(3) Next iEnd SubPrivate Sub Command2_Click() For i = 1 To 19 For j = i

29、 + 1 To 20 If A(i) A(j) Then t = A(i) A(i) = A(j) A(j) = t End If Next j Next i Text2.Text = For i = 1 To 20 Text2.Text = Text2.Text & Str(A(i) & Space(3) Next iEnd Sub7-9Dim a(1 To 6, 1 To 6), b(1 To 6, 1 To 6)Private Sub Command1_Click()RandomizePicture1.ClsFor i = 1 To 6 For j = 1 To 6 a(i, j) =

30、Int(Rnd * 10) + 1 Picture1.Print Format(a(i, j), !); Next j Picture1.PrintNext iEnd SubPrivate Sub Command2_Click()RandomizePicture2.ClsFor i = 1 To 6 For j = 1 To 6 b(i, j) = a(j, i) Picture2.Print Format(b(i, j), !); Next j Picture2.PrintNext iEnd Sub7-11Dim a() As Integer, n As IntegerPrivate Sub

31、 Form_click() Form1.Cls n = Val(InputBox(請輸入行數(shù), , 10) ReDim a(1 To n, 1 To n) a(1, 1) = 1 For i = 2 To n a(i, 1) = 1 a(i, i) = 1 For j = 2 To i - 1 a(i, j) = a(i - 1, j - 1) + a(i - 1, j) Next j Next i For i = 1 To n For j = 1 To i Print Format(a(i, j), !); Next j Print Next iEnd Sub7-12Dim n As Int

32、eger, x As IntegerPrivate Sub Command1_Click() n = n + 1 控件數(shù)組的最大下標(biāo)值加1 Load Text1(n) 添加一個文本框 Text1(n).Visible = True 使新加的文本框可見 Text1(n).Left = Text1(n - 1).Left + Text1(n - 1).Width 使新加的文本框顯示在右側(cè) Load Label1(n) 添加一個標(biāo)簽 Label1(n).Visible = True 使新加的標(biāo)簽可見 Label1(n).Left = Label1(n - 1).Left + Label1(n - 1

33、).Width 使新加的標(biāo)簽顯示在右側(cè) If Form1.Width 0 Then 如果還有控件可以刪除 If Form1.Width - Text1(n).Width x Then Form1.Width = x Else Form1.Width = Form1.Width - Text1(n).Width End If Unload Text1(n) 刪除文本框控件數(shù)組的最后一個元素 Unload Label1(n) 刪除標(biāo)簽控件數(shù)組的最后一個元素 n = n - 1 控件數(shù)組的最大下標(biāo)值減1 Else MsgBox 不能再刪除了 End IfEnd SubPrivate Sub Comm

34、and3_Click() For i = 0 To n Label1(i).Caption = Text1(n - i).Text Next iEnd SubPrivate Sub Form_Load() x = Form1.WidthEnd SubP1678-2Function area(a, b, c) p = (a + b + c) / 2 area = Sqr(p * (p - a) * (p - b) * (p - c)End FunctionPrivate Sub Command1_Click() a = Val(Text1.Text) b = Val(Text2.Text) c

35、= Val(Text3.Text) d = Val(Text4.Text) e = Val(Text5.Text) f = Val(Text6.Text) g = Val(Text7.Text) 求第一個三角形的面積 area1 = area(a, f, e) 求第二個三角形的面積 area2 = area(f, g, d) 求第三個三角形的面積 area3 = area(b, c, g) 求多邊形面積 areasum = area1 + area2 + area3 Label1.Caption = Format(areasum, 0.000)End Sub8-3Function f(k As

36、 Integer) As Long Dim sum As Long sum = 0 For i = 1 To k sum = sum + i Next i f = sumEnd FunctionPrivate Sub Command1_Click() Dim m As Integer, n As Integer, p As Integer Dim y As Single m = Val(Text1.Text) n = Val(Text2.Text) p = Val(Text3.Text) y = (f(m) + f(n) / f(p) Text4.Text = Format(y, 0.0000

37、)End Sub8-5Function f(k As Integer) As Long Dim sum As Long sum = 0 For i = 1 To k sum = sum + i Next i f = sumEnd FunctionPrivate Sub Command1_Click() Dim m As Integer, n As Integer, p As Integer Dim y As Single m = Val(Text1.Text) n = Val(Text2.Text) p = Val(Text3.Text) y = (f(m) + f(n) / f(p) Tex

38、t4.Text = Format(y, 0.0000)End Sub8-7Sub s(k, sum) sum = 0 For i = 1 To k sum = sum + i Next iEnd SubPrivate Sub Form_Click() sum = 0 n = Val(InputBox(請輸入N) For i = 1 To n Call s(i, sum1) sum = sum + 1 / sum1 Next i MsgBox Str(sum)End SubP1969-1Private Sub Option1_Click() Shape1.FillColor = vbRedEnd

39、 SubPrivate Sub Option2_Click() Shape1.FillColor = vbBlueEnd SubPrivate Sub Option3_Click() Shape1.FillColor = vbGreenEnd SubPrivate Sub Option4_Click() Shape1.FillColor = vbYellowEnd SubPrivate Sub Option5_Click() Shape1.Shape = 3End SubPrivate Sub Option6_Click() Shape1.Shape = 1End SubPrivate Sub

40、 Option7_Click() Shape1.Shape = 0End SubPrivate Sub Option8_Click() Shape1.Shape = 2End Sub9-3Private Sub Command1_Click() addit = Trim(InputBox(請輸入書名, 注意) If addit Then List1.AddItem addit End IfEnd SubPrivate Sub Command2_Click() If List1.ListCount = 0 Then MsgBox 列表中已經(jīng)沒有書, , 注意 Exit Sub End If If

41、 List1.ListIndex = 0 Then List1.RemoveItem List1.ListIndex Else MsgBox 請先選擇某本書, , 注意 End IfEnd SubPrivate Sub Command3_Click() Select Case List1.ListIndex Case 0 MsgBox 不能上移, , 注意 Case -1 MsgBox 請先選擇, , 注意 Case Else n = List1.ListIndex a = List1.List(n - 1) List1.List(n - 1) = List1.List(n) List1.Li

42、st(n) = a List1.Selected(n - 1) = True End SelectEnd SubPrivate Sub Command4_Click() Select Case List1.ListIndex Case List1.ListCount - 1 MsgBox 不能下移, , 注意 Case -1 MsgBox 請先選擇, , 注意 Case Else n = List1.ListIndex a = List1.List(n + 1) List1.List(n + 1) = List1.List(n) List1.List(n) = a List1.Selected

43、(n + 1) = True End SelectEnd SubPrivate Sub Command5_Click() List1.Selected(0) = TrueEnd SubPrivate Sub Command6_Click() List1.Selected(List1.ListCount - 1) = TrueEnd Sub9-4Private Sub Combo1_Click() Select Case Combo1.Text Case 黑 Text1.ForeColor = vbBlack Case 白 Text1.ForeColor = vbWhite Case 紅 Text1.ForeColor = vbRed Case 綠 Text1.ForeColor = vbGreen Case 藍(lán) Text1.ForeColor = vbBlue Case 黃 Text1.ForeColor = vbYellow End SelectEnd SubPrivate Sub Combo2_Click() Select Case Combo2

展開閱讀全文
溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!