




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第1章1. 按要求设置窗体属性2在窗体上建立一个标签Label1。程序代码如下:Private Sub Form_Click() Label1.Caption = 你单击了窗体End SubPrivate Sub Form_DblClick() Label1.Caption = 你双击了窗体End Sub3 在窗体上建立两个文本框Text1(输入数)、Text2(输出数)和一个命令按钮Command1。两个文本框的Text属性均为空。Private Sub Command1_Click() Dim x As Single x = Val(Text1.Text) Text2.Text = 15 * xEnd Sub第2章13题:按要求完成操作练习。4 Private Sub Command1_Click() 最大化按钮 Form1.WindowState = 2 最大化End SubPrivate Sub Command2_Click() 还原按钮 Form1.WindowState = 0 还原End SubPrivate Sub Command3_Click() 最小化按钮 Form1.WindowState = 1 最小化End Sub5在窗体上建立三个文本框Text1(第一个数)、Text2(第二个数)、Text3(计算结果)和一个命令按钮Command1(“计算”)。 Private Sub Command1_Click() Dim x As Single Dim y As Single x = Val(Text1.Text) y = Val(Text2.Text) Text3.Text = x * x + y * yEnd Sub6. 在窗体上建立两个文本框Text1(输入一串字符)、Text2(输出结果)和一个命令按钮Command1。 Private Sub Command1_Click() Dim x As String x = Left(Text1.Text, 1) + Right(Text1.Text, 1) Text2.Text = xEnd Sub第3章1在窗体上建立一个文本框Text1(输入n值)、三个标签Label1(第一个随机数)、Label2(第二个随机数)和Label3(第三个随机数),以及一个命令按钮Command1。Private Sub Command1_Click() n = Val(Text1.Text) Randomize x = Int(1 + n * Rnd) Label1.Caption = 第一个随机数 + Str(x) x = Int(1 + n * Rnd) Label2.Caption = 第二个随机数 + Str(x) x = Int(1 + n * Rnd) Label3.Caption = 第三个随机数 + Str(x)End Sub2在窗体上建立了四个文本框Text1、Text2、Text3和Text4,以及一个命令按钮Command1(“交换”)和Command2(“合并”)。Private Sub Command1_Click() “交换” t = Text1.Text Text1.Text = Text2.Text Text2.Text = Text3.Text Text3.Text = tEnd SubPrivate Sub Command2_Click() “合并” t = Text1.Text + Text2.Text + Text3.Text Text4.Text = tEnd Sub3. (1) Rnd * 9000 + 1000 (2) Str(x) (3) Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1)4. Private Sub Command1_Click() 往左 Text1.Left = 0End SubPrivate Sub Command2_Click() 往右 Text1.Left = Form1.Width - Text1.WidthEnd SubPrivate Sub Command3_Click() 居中 Text1.Left = (Form1.Width - Text1.Width) / 2End Sub5. Private Sub Cmd1_Click() Lab1.Visible = True Lab1.Caption = 您已下达显示命令End SubPrivate Sub Form_Click() Cmd1.Visible = TrueEnd Sub6. Private Sub Form_KeyPress(KeyAscii As Integer) Show Print 输入字符:; Chr(KeyAscii), ASCII码为; KeyAsciiEnd SubPrivate Sub Form_DblClick() ClsEnd Sub 7. 产生这三个消息框的相应语句是: 产生第1个消息框:x = MsgBox(在这里显示提示信息, 4 + 0, 请确认) 产生第2个消息框:x = MsgBox(在这里显示 + Chr(13) + 提示信息,3 + 0,请确认) 产生第3个消息框:x = MsgBox(在这里显示+Chr(13)+提示信息,2 + 16 + 0,请确认)第4章1. 在窗体上建立两个文本框Text1(输入数)及Text2(显示结果),一个命令按钮Command1(“判断”)。Private Sub Command1_Click() “判断” x = Val(Text1.Text) If x Mod 2 = 0 Then Text2.Text = 偶数 Else消息 Text2.Text = 奇数 End IfEnd Sub2窗体上建立了一个文本框Text1,用于显示结果。Private Sub Form_Load() x = Val(InputBox(请输入星期几(06) Select Case x Case Is = 0 Text1.Text = 星期日(Sunday) Case Is = 1 Text1.Text = 星期一(Monday) Case Is = 2 Text1.Text = 星期二(Tuesday) Case Is = 3 Text1.Text = 星期三(Wednesday) Case Is = 4 Text1.Text = 星期四(Thursday) Case Is = 5 Text1.Text = 星期五(Friday) Case Is = 6 Text1.Text = 星期六(Saturday) Case Else Text1.Text = 输入错误 End SelectEnd Sub3窗体上建立了一个文本框Text1(“输入口令”)和一个命令按钮Command1(“检查”)。Private Sub Command1_Click() “检查” x = Text1.Text If x = 12345678 Then MsgBox (欢迎你用机!) Else MsgBox (对不起,口令错) End If Text1.Text = Text1.SetFocusEnd SubPrivate Sub Form_Load() Text1.Text = Text1.MaxLength = 8 Text1.PasswordChar = *End Sub4窗体上建立了两个文本框Text1(输入字符串)及Text2(转换结果),一个命令按钮Command1(“清除”)。Private Sub Command1_Click() “清除” Text1.Text = Text2.Text = Text1.SetFocusEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) Dim s As String * 1 s = Chr(KeyAscii) Select Case s Case A To Z s = LCase(s) Case a To z s = UCase(s) Case Else s = * End Select Text2.Text = Text2.Text + sEnd Sub5 分别选择”红”、 ”绿”、 ”蓝”复选框后,单击命令按钮Command1时,通过RGB函数调配的颜色作为一个标签的背景色(BackColor)。Private Sub Command1_Click() r = 0: g = 0: b = 0 If Check1.Value = 1 Then ”红”复选框 r = 255 End If If Check2.Value = 1 Then ”绿”复选框 g = 255 End If If Check3.Value = 1 Then ”蓝”复选框 b = 255 End If Label1.BackColor = RGB(r, g, b)End Sub6程序代码如下:Private Sub Form_Load() LabClk.Caption = 0 LabClk.Alignment = 1 LabClk.BorderStyle = 1 LabClk.FontSize = 22 LabClk.FontName = 黑体 TimClk.Interval = 1000End Sub Private Sub TimClk_Timer() LabClk.Caption = Val(LabClk.Caption) + 1End Sub7 (1) Chr(KeyAscii) (2) ElseIf Chr(KeyAscii) (3) CheC = CheC - 1 (4) CheC (5) Is 0 或 Else第5章1. 和数为:1.21。程序代码如下:Private Sub Form_Load() Show s = 0 For k = 1 To 100 s = s + 1 / (1 + k * 4) Next k Print sEnd Sub2. 程序代码如下:Private Sub Form_Load() Dim i As Integer, a As Integer, b As Integer, c As Integer Show For i = 100 To 999 a = Int(i / 100) b = Int(i - 100 * a) / 10) c = i - 100 * a - 10 * b If a * a * a + b * b * b + c * c * c = i Then Print i End If Next iEnd Sub3. 在窗体上建立一个文本框Text1(初始值)、一个列表框List1(显示结果)和一个命令按钮Comd1(“查找”)。Private Sub Comd1_Click() “查找” Dim n As Integer n = Val(Text1.Text)List1.Clear:k = 0 Do While k = A And t = 0.00001 Print a; 的平方根为; xn1End Sub第6章1. 程序代码如下: Private Sub Form_Load() Show Dim a(100) As Single n = Val(InputBox(输入个数n) Print 处理前数据 : For k = 1 To n a(k) = Val(InputBox(请输入第 & k & 个数) Print a(k); Next k Print M = Int(n / 2) For k = 1 To M h = n - k + 1 t = a(h):a(h) = a(k):a(k) = t Next k Print 处理的结果 : For k = 1 To n Print a(k); Next kEnd Sub2. 程序代码如下: Private Sub Form_Load() Dim a(6, 6) As Integer Show For i = 1 To 6 For j = 1 To 6 Select Case i Case Is j a(i, j) = 2 Case Is = j a(i, j) = 0 End Select Print a(i, j); Next j Print Next i For i = 1 To 6 t = a(1, i):a(1, i) = a(6, i):a(6, i) = t Next i Print: Print For i = 1 To 6 For j = 1 To 6 Print a(i, j); Next j Print Next iEnd Sub3在窗体上建立两个列表框List1(处理前数据)和List2(处理后数据),以及标签Label1。程序代码如下: Private Sub Form_Load() Dim a(100) As Integer, b(100) As Integer Randomize n = 100 For i = 1 To n 输入数组a的n个元素 x = Int(20 * Rnd) List1.AddItem x a(i) = x Next i k = 0 For i = 1 To n 删除零元素 If a(i) 0 Then k = k + 1 : b(k) = a(i) : List2.AddItem b(k) End If Next i Label1.Caption = 数组中零元素个数: + Str(n - k)End Sub4(1) g(x - 10) + 1 (2) n - 1 (3) g(t) g(j) (4) m = s(t): s(t) = s(k): s(k) = m 5在窗体上建立4行3列共12个元素的文本框控件数组Text1(0)Text1(11)Private Sub Form_Load() Dim t(12) As String Randomize For k = 1 To 12 t(k) = Empty 初始安排12个位置均为Empty Next k For h = 65 To 74 代表A至J,每次随机安排一个字母 Do While True 随机查找一个空位 p = Int(1 + 12 * Rnd) 产生112随机数 If t(p) = Empty Then t(p) = Chr(h) Exit Do End If Loop Next h For k = 1 To 12 Text1(k - 1).Text = t(k) 显示座位分配情况 Next kEnd Sub第7章1. 在窗体上建立四个文本框Text1和一个命令按钮Command1(“检验”)。文本框Text1Text3用于输入,Text4用于输出结果。Private Sub Command1_Click() Dim a As String, b As String, c As String a = Trim(Text1.Text) b = Trim(Text2.Text) c = Trim(Text3.Text) If che(a) And che(b) And che(c) Then Text4.Text = Val(a) + Val(b) + Val(c) Else Text4.Text = 存在非数字字符 End IfEnd SubFunction che(x As String) As Boolean 若存在非数字字符,函数值为假 che = True For k = 1 To Len(x) s = Mid(x, k, 1) If s 9 Then che = False Exit For End If Next kEnd Function2在窗体上建立七个文本框Text1Text7和一个命令按钮Command1(“比较”)。Text1Text6用于输入,Text7用于输出结果。Private Sub Command1_Click() a = Val(Text1.Text):b = Val(Text2.Text):c = Val(Text3.Text) d = Val(Text4.Text):e = Val(Text5.Text):f = Val(Text6.Text) Call max(a, b, c, m) Call max(m, d, e, m) Call max(m, f, f, m) Text7.Text = mEnd SubSub max(x, y, z, m) 标准模块文件 If x y Then m = x Else m = y End If If m z Then m = z End IfEnd Sub3. (1) s (2) Mid(s, p+1) (3) n4. 程序代码如下:Private Sub Form_Load() Dim x As Single, n As Integer, y As Double x = InputBox(x=, 求X的n次方) n = InputBox(n=, 求X的n次方) y = Power(x, n) Show Print x; 的; n; 次方=; Format(y, #,#.#)End SubFunction Power(x As Single, n As Integer) As Double If n 1 Then Power = Power(x, n - 1) * x Else Power = x End IfEnd Function5 在窗体上设置三个窗体Form1Form3。Form1中建立了两个文本框Text1(“用户名”)和Text2(“密码”),以及命令按钮Command1(“判断”)。Form2中建立了一个文本框Text1(其Text属性值为“欢迎你使用本系统”)和命令按钮Command1(“返回”)。Form3中建立了一个文本框Text1(其Text属性值为“对不起,请向管理员查询”)和命令按钮Command1(“退出”)。Dim n As IntegerPrivate Sub Command1_Click() 窗体Form1的“判断” usern = Trim(Text1.Text):passw = Trim(Text2.Text) If usern = username And passw = password Then Form1.Hide Form2.Show Else n = n + 1:Text1.SetFocus If n = 3 Then Form1.Hide Form3.Show End If End If Text1.Text = :Text2.Text = End SubPrivate Sub Form_Activate() Text1.Text = :Text2.Text = Text1.SetFocusEnd SubPrivate Sub Command1_Click() 窗体Form2的“返回” Form2.Hide Form1.ShowEnd SubPrivate Sub Command1_Click() 窗体Form3的“退出” Unload Form1 Unload Form2Unload Form3 EndEnd Sub 6. (1) Form1窗体模块程序代码:Private Sub Form_Load() RandomizeEnd SubPrivate Sub Command1_Click() 生成随机数 Dim s As String s = For i = 1 To 10 a(i) = Int(11 + 90 * Rnd) s = s + Str(a(i) + , Next i Text1.Text = Left(s, Len(s) - 1)End SubPrivate Sub Command2_Click() 求最大数 Text2.Text = Max()End SubPrivate Sub Command3_Click() 打开排序窗口 Form1.Hide 隐藏主窗体 Form2.Show 显示“排序”窗体End SubPrivate Sub Command4_Click() 结束 Unload Form1 隐藏主窗体 Unload Form2 显示“排序”窗体 EndEnd Sub(2) Form2窗体模块程序代码:Private Sub Command1_Click() “排序” Dim t As String Call Sort(t) Text1.Text = tEnd SubPrivate Sub Command2_Click() “返回” Form2.Hide 隐藏“排序”窗体 Form1.Show 显示主窗体End Sub(3) 标准模块程序代码:Public a(1 To 10) As SingleFunction Max() As Single 求最大值 Dim m As Single m = a(1) For i = 2 To 10 If m a(j) Then t = a(i): a(i) = a(j): a(j) = t End If Next j s = s + Str(a(i) + , Next i s = s + Str(a(10)End Sub第8章1. 程序代码如下:Dim d(1 To 20) As IntegerPrivate Sub Command1_Click() 产生随机数 For i = 1 To 20 d(i) = Int(1 + 99 * Rnd) List1.AddItem d(i) Next iEnd SubPrivate Sub Command2_Click() 保存 Open MyFile3.txt For Output As #1 For i = 1 To 20 Write #1, d(i) Next i Close #1End SubPrivate Sub Command3_Click() 读出 Open MyFile3.txt For Input As #1 Do While Not EOF(1) Input #1, x List2.AddItem x Loop Close #1End SubPrivate Sub Command4_Click() 结束 EndEnd Sub2 本程序的用户界面和程序代码较为复杂,请见具体程序文件。第9章1. 程序代码如下:Private Sub Form_load() Dim x(3) As Single, y As Single On Error GoTo errln 以后出错时转移到errln y = 2 / 0 产生除数为0的错误 x(4) = 1 产生下标越界的错误 MsgBox (终止程序的运行) Unload Me 卸载窗体 Enderrln: 标号Select Case Err.Number Case 11 除数为0的错误码为11 MsgBox (除数为0(错误码为11),跳过该错误) Resume Next 返回 Case 9 下标越界的错误码为9 MsgBox (下标越界(错误码为9),跳过该错误) Resume Next 返回 Case Else 其他错误处理 MsgBox (错误发生在 & Err.Source _ & , 代码为 & Err.Number _ & , 即 & Err.Description) End SelectEnd Sub2改正后的程序代码如下:Private Sub Form_Load() Show For i = 1 To 11 Print Tab(20 - i); For j = 1 To 2 * i - 1 If j 9 Then k = k + 7 Print Chr(k + 48); Next j Next iEnd Sub3(1) n = n + 1 (2) d(1, j) = d(3, j) (3) d(i, 2) = d(i, 4) (4) i = j (5) d(i, j) = d(i, j) + 1 (6) n = 0 (7) Text1.Text第10章1在窗体上建立一个水平滚动条HScroll1和一个文本框Text1。程序代码如下:Private Sub Form_Load() HScroll1.Max = 1000 HScroll1.Min = 0 HScroll1.LargeChange = 5 HScroll1.LargeChange = 10 HScroll1.Value = 500End SubPrivate Sub HScroll1_Change() Text1.Text = HScroll1.ValueEnd SubPrivate Sub HScroll1_Scroll() Text1.Text = HScroll1.ValueEnd Sub 2. 在窗
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年村级养老服务平台保洁员招聘题集
- 课件中使用的抽号
- 2025年车队安全员招聘面试模拟题及高频问题
- 2025年广播节目主持人专业技能考核试题及答案解析
- 2025年光伏初级面试题及答案
- 2025年安全知识竞赛试题及答案
- 课件《地球爷爷生病了》
- 早教课件教学设计及反思
- 机电基础知识培训课件
- 教学多媒体课件四六原则
- 北京员工待岗管理办法
- 停工缓建项目管理办法
- 淋巴水肿健康科普
- 采购应急计划管理办法
- 上海选调生面试题和考官用题本及答案21套
- 2025年学校食堂从业人员食品安全知识培训考试试题及答案
- 2025年国家电投校园招聘笔试考点考试题库及答案
- 让情绪有着落-2025年情绪营销8大趋势洞察报告
- 教师校园安全培训课件
- 头皮健康与头发生长关系的研究
- Odoo面试题及答案
评论
0/150
提交评论