vb的一些过程代码.doc

上传人:仙人指路1688 文档编号:2389310 上传时间:2023-02-17 格式:DOC 页数:49 大小:92KB
返回 下载 相关 举报
vb的一些过程代码.doc_第1页
第1页 / 共49页
vb的一些过程代码.doc_第2页
第2页 / 共49页
vb的一些过程代码.doc_第3页
第3页 / 共49页
vb的一些过程代码.doc_第4页
第4页 / 共49页
vb的一些过程代码.doc_第5页
第5页 / 共49页
点击查看更多>>
资源描述

《vb的一些过程代码.doc》由会员分享,可在线阅读,更多相关《vb的一些过程代码.doc(49页珍藏版)》请在三一办公上搜索。

1、Adodc1.ConnectionStringAdodc1.ControlSourcePrivate Sub CommandButton1_Click()Sheet1.ActivateDim i As IntegerDim j As Integer For i = 1 To 10 For j = 1 To 10 Sheet1.Cells(i, j) = i * j Next j Next i End SubPrivate Sub Command1_Click()Dim x As Integer, y As Integerx = 18: y = 15Call value(x, y)Print x

2、=; y=; yEnd SubPrivate Sub value(ByVal m As Integer, ByVal n As Integer)m = m + 2: n = n + 5Print m=; m, n=; nEnd SubPrivate Sub Command1_Click()If Data1.Recordset.RecordCount = 0 ThenMsgBox 没有记录ElseData1.Recordset.MoveFirstEnd IfEnd SubPrivate Sub commandp_click()If Data1.Recordset.RecordCount = 0

3、ThenMsgBox 没有记录ElseIf Data1.Recordset.BOF ThenMsgBox 这是第一条记录Data1.Recordset.MoveFirstElseData1.Recordset.MovePreviousIf Data1.Recordset.BOF ThenData1.Recordset.MoveFirstMsgBox 这是第一条记录End IfEnd IfEnd IfEnd SubPrivate Sub Form_Load()Data1.Connect = accessData1.DatabaseName = App.Path + class.mdbData1.

4、RecordSource = 学院表End SubPrivate Sub Command2_Click()Adodc1.Recordset.MoveLastEnd SubPrivate Sub Command3_Click()Adodc1.Recordset.MoveFirstAdodc1.Recordset.DeleteEnd SubPrivate Sub Command1_Click()Text3.Text = Text1.Text + Text2.TextEnd SubPrivate Sub Command2_Click()Adodc1.Recordset.MoveNextIf Adod

5、c1.Recordset.EOF Then Adodc1.Recordset.MoveLast MsgBox this is last contentEnd IfEnd SubPrivate Sub CommandButton1_Click()Sheet1.ActivateDim i As Integer, j As Integer For i = 1 To 10 For j = 1 To 10 Sheet1.Cells(i, j) = i * j Next j Next i End SubPrivate Sub UserForm_Click()Dim i As Integer, j As I

6、ntegeri = 1: j = 2 Print j; Do While i = 100 Print i; t = i i = i + j j = tLoopEnd Sub Private Sub Form_Activate()Print 窗体1的activate时间被激发End SubPrivate Sub Command1_Click() Form2.ShowEnd SubPrivate Sub Command2_Click()Me.Caption = 更改标题EndEnd SubPrivate Sub Form_Activate()Print 窗体1的activate时间被激发End S

7、ubPrivate Sub Command1_Click()Form2.HideForm1.ShowEnd SubPrivate Sub Command2_Click() Me.Caption = 更改标题End SubPrivate Sub Command3_Click()Form1.ClsForm1.ShowEnd SubPrivate Sub Form_Load()Command1.Caption = 复制End SubDim temptext As StringPrivate Sub cmdcopy_Click()temptext = Text1.SelTextIf Text1 The

8、n cmdpaste.Enabled = TrueElse: MsgBox 请先清除文本End If End SubPrivate Sub cmdcut_Click()temptext = Text1.SelTextIf temptext ThenText1.SelText = cmdpaste.Enabled = TrueElseMsgBox 请先选中文本End IfEnd SubPrivate Sub cmdpaste_Click()Text2.Text = temptextEnd Sub红绿灯Dim path As StringPrivate Sub cmdgreen_Click() P

9、icture1.Picture = LoadPicture(path + TRFFC10A.ico)End SubPrivate Sub cmdred_Click() Picture1.Picture = LoadPicture(path + TRFFC10C.ico)End SubPrivate Sub cmdyellow_Click() Picture1.Picture = LoadPicture(path + TRFFC10B.ico)End SubPrivate Sub Form_Load() path = C:Program FilesMicrosoft Visual StudioC

10、ommonGraphicsIconsTrafficEnd Sub选择题窗口Private Sub Command1_Click()Dim ans As StringIf Option1.Value = True Then ans = AIf Option2.Value = True Then ans = BIf Option3.Value = True Then ans = CIf Option4.Value = True Then ans = D Text1.Text = ansEnd Sub字体变化Private Sub Check1_Click() If Check1.Value = 1

11、 Then Text1.FontBold = True Else Text1.FontBold = False End If End Sub Private Sub Check2_Click() If Check2.Value = 1 Then Text1.FontItalic = True Else Text1.FontItalic = False End IfEnd Sub Private Sub Check3_Click() If Check3.Value = 1 Then Text1.FontUnderline = True Else Text1.FontUnderline = Fal

12、se End If End Sub Private Sub Check4_Click() If Check4.Value = 1 Then Text1.FontStrikethru = True Else Text1.FontStrikethru = False End If End Sub 米粉调查Private Sub Command1_Click()Dim msg As Stringmsg = 您的孩子If Option1.Value = True Then msg = msg + Option1.CaptionIf Option2.Value = True Then msg = msg

13、 + Option1.CaptionIf Option3.Value = True Then msg = msg + Option1.Captionmsg = msg + 使用过的米粉牌子有:If Check1.Value = 1 Then msg = msg + Check1.Caption + If Check2.Value = 1 Then msg = msg + Check1.Caption + If Check3.Value = 1 Then msg = msg + Check1.Caption + If Check4.Value = 1 Then msg = msg + Check

14、1.Caption + text1.Text = msgEnd Sub增加索引Private Sub Form_Load()List1.AddItem 西游记List1.AddItem 傲慢与偏见List1.AddItem 水壶传List1.AddItem 王子复仇记List1.AddItem 白雪公主List1.AddItem 红楼梦List1.AddItem 灰姑娘List1.AddItem 牛虻Cmddelete.Enabled = FalseEnd SubPrivate Sub List2_Click()Cmddelete.Enabled = (List2.ListIndex -1)E

15、nd SubPrivate Sub cmdadd_Click()List2.AddItem List1.Text End SubPrivate Sub Cmddelete_Click()List2.RemoveItem List2.ListIndexCmddelete.Enabled = (List2.ListIndex -1)End Sub选择学历Private Sub Combo1_Click()Text1.Text = 你的学历是 & Combo1.TextEnd SubPrivate Sub Combo1_KeyPress(KeyAscii As Integer) If KeyAsci

16、i = 13 Then Text1.Text = 你的学历是 & Combo1.Text End If End SubPrivate Sub Form_Load()Combo1.AddItem 研究生Combo1.AddItem 本科Combo1.AddItem 大专Combo1.AddItem 大专以下End SubPrivate Sub Form_Load()Text1.Text = 0Text2.Text = 30Label3.Caption = 系统时间是: & TimeEnd Sub时间控件Private Sub Timer1_Timer()If Val(Text1.Text) =

17、30 Then EndElse Text1.Text = Val(Text1.Text) + 1 Text2.Text = 30 - Val(Text1.Text) Label3.Caption = 系统时间: & TimeEnd IfEnd Sub三角形Private Sub Command2_Click()Dim a As Integer, b As Integer, c As Integera = Val(Txta.Text): b = Val(Txtb.Text): c = Val(Txtc.Text)If a 0 And b 0 And c 0 ThenIf a + b c And

18、a + c b And b + c a Then Picture.Print 以 & a&; , & b&; , & c&; 为三边可以构成一个三角形Else Picture.Print 以 & a&; , & b&; , & c&; 为三边不能构成一个三角形End IfEnd Sub三角形面积Private Sub Cmdshow_Click() Dim r As Single, ans As Single, pi As Single pi = 3.14 r = Val(Text1.Text) If r 0 Then If Check1.Value = 1 Then ans = 2 * pi

19、 * r List1.AddItem 圆周为 & ans End If If Check2.Value = 1 Then ans = pi * r * r List1.AddItem 圆周为 & ans End If Else List1.AddItem 非法数据 End IfEnd Sub 键盘事件Private Sub Text1_KeyPress(KeyAscii As Integer) Dim x As Integer If KeyAscii = 13 Then If Len(Text1.Text) = 1 And Text1.Text = a And Text1.Text = z T

20、hen x = Asc(Text1.Text) If x Asc(z) Then Text2.Text = Chr(x + 1) Else Text2.Text = Chr(x + 1 - 26) End If Else Text2.Text = 数据非法! End If End If End Sub自动拖放 p63Private Sub Form_Load()Picture1.Picture = LoadPicture(App.Path + MOON02.ICO)Picture2.Picture = LoadPicture(App.Path + MOON04.ICO)Picture1.Dra

21、gIcon = LoadPicture(App.Path + MOON03.ICO)End SubPrivate Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)Picture1.Picture = LoadPicture(App.Path + MOON04.ICO)Picture2.Picture = LoadPicture(App.Path + MOON02.ICO)End Sub拖放国旗 p65Dim flag1 As Boolean, flag2 As BooleanPrivate Sub Form_D

22、ragDrop(Source As Control, X As Single, Y As Single)If flag1 = True Then Image1.Move X.Y if x=shape2.left and x=shape2.top and y=shape2.left and x=shape2.top and y=shape2.top+shap2.height thenMsgBox 选错了! End IfEnd IfEnd SubPrivate Sub Form_Load()Image1.Picture = LoadPicture(App.Path + flagflgusa02.i

23、co)Image2.Picture = LoadPicture(App.Path + flagflguk.ico)End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)flag1 = Trueflag2 = FalseImage1.Drag 1Image1.DragIcon = LoadPicture(App.Path + flagflgusa02.ico)End SubPrivate Sub Image1_MouseUp(Button As Integ

24、er, Shift As Integer, X As Single, Y As Single)flag1 = Falseimageq.Drag 2End SubPrivate Sub Image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)flag2 = Trueflag1 = FalseImage2.drag1Image2.DragIcon = LoadPicture(App.Path + flagflguk.ico)End SubPrivate Sub Image2_MouseUp(But

25、ton As Integer, Shift As Integer, X As Single, Y As Single)flag2 = FalseImage2.Drag 2End Subp68Private Sub mnucircle_Click()Shape1.Shape = 3End SubPrivate Sub muncross_Click()Shape1.FillStyle = 6End SubPrivate Sub mundcross_Click()Shape1.FillStyle = 7End SubPrivate Sub munsquare_Click(Index As Integ

26、er)Shape1.Shape = 1End Sub闹钟p160Private Sub Command1_Click()Timer1.Enabled = Not Timer1.EnabledEnd SubPrivate Sub Timer1_Timer()Dim d As Dated = Text1.TextIf Hour(Time) = Hour(d) And Minute(Time) = Minute(d) Then BeepEnd Sub根号运算 p161Private Sub Command1_Click() Dim x As Single, y As Single x = Val(T

27、ext1.Text) If x 0 Then MsgBox x不能小于0 Else y = Sqr(x) Text2.Text = Str(y) End If End Sub计算行李 p163Private Sub Command1_Click() Dim x As Single, y As Single x = Val(Text1.Text) If x 30 Then y = 0 ElseIf x = 50 Then y = (x - 30) * 10 Else y = (x - 50) * 20 + 20 * 10 End If Text2.Text = yEnd Sub判断年龄 p164

28、Private Sub Command1_Click()If Option1.Value = True Then If Val(Text1.Text) 14 Then MsgBox hello,boy Else MsgBox hello,guy End IfElse If Val(Text1.Text) 14 Then MsgBox hello,girl Else MsgBox hello,miss End IfEnd IfEnd Sub计算器 p167Private Sub Form_Load()Combo1.AddItem +Combo1.AddItem -Combo1.AddItem *

29、Combo1.AddItem /End SubPrivate Sub Command1_Click() Select Case Combo1.Text Case + Text3.Text = Val(Text1.Text) + Val(Text2.Text) Case + Text3.Text = Val(Text1.Text) - Val(Text2.Text) Case * Text3.Text = Val(Text1.Text) * Val(Text2.Text) Case / If Val(Text2.Text) 0 Then Text3.Text = Val(Text1.Text)

30、/ Val(Text2.Text) Else MsgBox p被0除 Text2.Text = Text2.SetFocus End If End SelectEnd Sub求最大值和最小值 p169Private Sub Command1_Click() Dim a As Integer, b As Integer a = Val(Text1.Text) b = Val(Text2.Text) If a b Then Max = a Else Max = b If a b Then Min = a Else Min = b MsgBox Max & 是最大值 & Min & 是最小值End

31、Sub输入字母判断 p169Private Sub Text1_KeyPress(KeyAscii As Integer)If (KeyAscii Asc(z) And (KeyAscii Asc(Z) Then KeyAscii = 0End Sub密码设置 p170Private Sub Command2_Click() If Text1.Text = Or Text2.Text = Then MsgBox 请输入完整信息! Else If Text2.Text 2008 Then MsgBox 密码错误! Text1.Text = Text1.SetFocus Else MsgBox T

32、ext1.Text & ,欢迎你! End If End IfEnd Sub计算总分和平均分 p171Private Sub Command1_Click() Dim sum As Integer, n As Integer If Check1.Value = 1 Then sum = sum + Val(Text1.Text): n = n + 1 If Check2.Value = 1 Then sum = sum + Val(Text3.Text): n = n + 1 If Check3.Value = 1 Then sum = sum + Val(Text3.Text): n = n

33、 + 1 If Option1.Value Then Text4.Text = n & 门数总分: & vbCrLf & sum Else If n 0 Then Text4.Text = n & 门课平均分 & vbCrLf & sum / n End IfEnd Sub排序 p172Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer Dim temp As Integer a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) If

34、 a b Then temp = a: a = b: b = temp If a c Then temp = a: a = c: c = temp If b c Then temp = b: b = c: c = temp Text1.Text = a Text2.Text = b Text3.Text = cEnd Sub计算方程根 p172Private Sub Command1_Click() Dim a As Double, b As Double, c As Double Dim delta As Double Dim x1 As Double, x2 As Double a = V

35、al(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) If a 0 Then delta = b * b - 4 * a * c If delter 0 Then x1 = (-b + Sqr(delta) / (2 * a) x2 = (-b - Sqr(delta) / (2 * a) Text4.Text = x1= & Chr(13) & Chr(10) & x2= & x2 ElseIf delta = 0 Then x1 = -b / (2 * a) Text4.Text = 两个相同的结果,x1=x2= & x1 Else

36、x1 = -b / (2 * a) x2 = Sqr(-delta) / (2 * a) Text4.Text = x1= & x1 & + & x2 & i & Chr(13) & Chr(10) & x2= & x1 & - & x2 & i End If End If End Sub计算3,5,7 p173Private Sub Command1_Click() Dim x As Integer x = Val(Text1.Text) If x Mod 3 = 0 And x Mod 5 = 0 And x Mod 7 = 0 Then MsgBox 能被3,5,7整除 ElseIf x

37、 Mod 3 = 0 And x Mod 5 = 0 And x Mod 7 0 Then MsgBox 能被3,5整除 ElseIf x Mod 3 = 0 And x Mod 7 = 0 And x Mod 5 0 Then MsgBox 能被3,7整除 ElseIf x Mod 7 = 0 And x Mod 5 = 0 And x Mod 3 0 Then MsgBox 能被5,7整除 ElseIf x Mod 3 = 0 Then MsgBox 能被5整除 ElseIf x Mod 5 = 0 Then MsgBox 能被5整除 ElseIf x Mod 7 = 0 Then Msg

38、Box 能被7整除 Else MsgBox 不能被3,5,7任一数值整除 End IfEnd Sub计算1到100 p179Private Sub Command1_Click()Dim i As Integer, sum As Integersum = 0For i = 1 To 100sum = sum + iNext iText1.Text = sumEnd Sub计算被3整除 p179Private Sub Command1_Click()Dim x As Integer, n As IntegerFor x = 1 To 200 If x Mod 3 = 0 Then Print x

39、; n = n + 1 If n Mod 10 = 0 Then Print End If Next x Print End Sub验证谷角猜想 p181Private Sub Command1_Click()Dim x As Integer, n As IntegerFor x = 3 To 200 Step 3Print x;n = n + 1If n Mod 10 = 0 Then Print Next x PrintEnd SubPrivate Sub Command1_Click() Dim n As Integer Cls n = Val(InputBox(请输入一个正整数) Pr

40、int n; If n 0 Then Do While n 1 If n Mod 2 = 1 Then n = n * 3 + 1 Else n = n / 2 End If Print -; n; Loop End If End Sub随机数的平均数 p183Private Sub Form_Click()Dim n As Integer, x As Integer, sum As Integer n = Fix(Val(InputBox(请输入数据个数) Do Until n 0 If MsgBox(输入错误,需要从新输入吗?, vbYesNo) = vbYes Then n = Fix(

41、Val(InputBox(请输入数据个数) Else Exit Sub End If Loop sum = 0 For i = 1 To n x = Int(Rnd * 100) sum = sum + x Print x: If i Mod 10 = 0 Then Print Next i Print Print n; 个数的平均值等于=; sum / n End Sub阶乘p 186Private Sub Command1_Click() Dim i As Integer, s As Double i = 1 Do While i = 10 s = 1 For j = 1 To i s = s * j Next j Print i; !=; s i = i + 1 LoopEnd Sub九九乘法表 p187Private Sub Command1_Click() Dim i As Int

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号