VB计算器的程序设计(附代码).doc_第1页
VB计算器的程序设计(附代码).doc_第2页
VB计算器的程序设计(附代码).doc_第3页
VB计算器的程序设计(附代码).doc_第4页
VB计算器的程序设计(附代码).doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

计算器的VB程序设计要求: 1)设计一个可以进行四则运算的简单计算器。该计算器可以进行加、减、乘、除、求模(取余)等简单的四则运算,并具有符合计算器日常使用习惯的容错纠错功能。具体步骤如下: 在界面上建立按钮控件数组:首先在窗体中置入一个命令按钮控件后,将其激活并点击右键通过“复制”、“粘贴”的方法依次产生19个一样的命令按钮控件,其中在创建第一个“粘贴”控件时VB会询问“是否要创建控件数组?”回答“是”即可开始依次创建该控件数组。 按钮属性的设置:将各按钮的caption属性分别设置为0,1,29,、,/,Mod,cls,Exit,注意在设置这些属性时其值与按钮控件的Index属性的对应性。 其它控件的属性设置:文本框作为显示操作数和结果的控件,应遵循一般计算器的显示习惯,将其Alignment即对齐属性设置为“Right”,此外,将各控件相关的字体、字号等设置为统一风格。 在程序的通用区定义四个窗体层变量:num1、num2、sum、act、前三个为双精度、act为整型变量。 编写进行四则运算所需的程序作为命令按钮的单击事件过程。 实验三参考代码一: Dim num1 As Double, num2 As Double Dim sum As Double Dim act As Integer Private Sub Form_Load() num1 = 0 num2 = 0 sum = 0 End Sub Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 If Text1.Text = Then Text1.Text = 0 Else Text1.Text = Text1.Text + 0 End If Case 1 If Text1.Text = Then Text1.Text = 1 Else Text1.Text = Text1.Text + 1 End If Case 2 If Text1.Text = Then Text1.Text = 2 Else Text1.Text = Text1.Text + 2 End If Case 3 If Text1.Text = Then Text1.Text = 3 Else Text1.Text = Text1.Text + 3 End If Case 4 If Text1.Text = Then Text1.Text = 4 Else Text1.Text = Text1.Text + 4 End If Case 5 If Text1.Text = Then Text1.Text = 5 Else Text1.Text = Text1.Text + 5 End If Case 6 If Text1.Text = Then Text1.Text = 6 Else Text1.Text = Text1.Text + 6 End If Case 7 If Text1.Text = Then Text1.Text = 7 Else Text1.Text = Text1.Text + 7 End If Case 8 If Text1.Text = Then Text1.Text = 8 Else Text1.Text = Text1.Text + 8 End If Case 9 If Text1.Text = Then Text1.Text = 9 Else Text1.Text = Text1.Text + 9 End If Case 10 If Text1.Text = Then Text1.Text = . Else Text1.Text = Text1.Text + . End If Case 11 num1 = CDbl(Text1.Text) 强制转换双精度型 Text1.Text = act = 1 Case 12 num1 = CDbl(Text1.Text) Text1.Text = act = 2 Case 13 num1 = CDbl(Text1.Text) Text1.Text = act = 3 Case 14 num1 = CDbl(Text1.Text) Text1.Text = act = 4 Case 15 num1 = CDbl(Text1.Text) Text1.Text = act = 5 Case 16 num1 = 0 num2 = 0 sum = 0 Text1.Text = Case 17 num2 = CDbl(Text1.Text) Select Case act Case 1 sum = num1 + num2 Case 2 sum = num1 - num2 Case 3 sum = num1 * num2 Case 4 sum = num1 / nu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论