vb2010实验报告-计算器的制作与实现_第1页
vb2010实验报告-计算器的制作与实现_第2页
vb2010实验报告-计算器的制作与实现_第3页
vb2010实验报告-计算器的制作与实现_第4页
vb2010实验报告-计算器的制作与实现_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

1、软件开发环境与工具实验报告实验一实验题目: 计算器的制作与实现 实验类型: 验证 实验地点: 软件实验室一 指导教师: 专业班级: 计算机科学与技术系班 姓 名: 20年10月25日一、实验目的:1、熟悉VB.NET程序开发环境,了解VB.NET应用程序设计的基本框架结构。2、掌握Windows Form的事件处理机制,以及如何在运行期创建控件。3、初步掌握VB.NET的基本编程方法和技巧。二、实验内容:设计一个简单的计算器程序,使之能够实现加、减、乘、除等基本的四则运算。三、实验设计思路: 先模拟地设计出计算器面板,包含各类按钮和结果输出框,然后写出各个触发事件,包含数字事件、运算符号事件、

2、等号事件等,之后再写各类运算函数,包括加法、减法、乘法和除法,最后于主函数中调用各功能及运算。四、实验步骤:1、打开Microsoft Visual Studio 2010,点击“新建项目”,在弹出的对话框中选择“Visual Basic/ Windows”项目类型,“模板”选择“Windows窗体应用程序”,在名称处将默认名WindowsApplication1改为“简易计算器”,然后指定该应用程序的保存路径,点击“确定”,进入窗体设计界面。2、调整好窗体的大小后,将鼠标移到左侧“工具箱”位置,自动弹出“工具箱”窗口,选择其中的“TextBox”控件对象并将其拖拽到窗体中,调整大小并将其拖动

3、到适当位置,在属性窗口中选定属性名“(Name)”,在右列中将其属性值设为“output”,用于显示数据。3、用同样的方法向窗体中添加19个Button控件,单击“Button1”控件,同样在属性窗口中选定属性名“(Name)”,在右列中将其属性值设为“zero”,并在属性窗口中选定属性名“Text”,在右列中将其属性值设为“0”。用同样的方法依次将其他Button控件的“(Name)”属性值分别设为“point”、“AllClean”、“equal”、“one”、“two”、“three”、“add”、“subtract”、“four”、“five”、“six”、“multiply”、“di

4、vide”、“seven”、“eight”、“nine”、“kai”、“guan”;“Text”属性值分别设为“.”、“AC(归零)”、“=”、“1”、“2”、“3”、“+”、“-”、“4”、“5”、“6”、“*”、“/”、“7”、“8”、“9”、“on”、“off”,最终界面如下:4、完成窗体和控件的布局及其属性设置后,双击要编写代码的命令按钮,进入代码编译器,开始编写程序代码。五、实验代码:Public Class Calculator Dim strdx() As String = "0", "0", "0" '声明一个

5、字符串,用以存取数值 Dim calcount1 As String = "0" Dim calcount2 As String = "0" Dim strvalue As Boolean = False Private Sub zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zero.Click If strdx(0) = "0" Then output.Text = strdx(0) & "."

6、 ElseIf strvalue = False Then strdx(0) = strdx(0) & "0" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "0" output.Text = strdx(0) End If End Sub Private Sub point_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles point.Click

7、strvalue = True strdx(0) = strdx(0) & "." output.Text = strdx(0) End Sub Private Sub AllClean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllClean.Click strdx(0) = "0" strdx(1) = "0" strdx(2) = "0" calcount1 = "0" ca

8、lcount2 = "0" strvalue = False output.Text = "0." End Sub Private Sub equal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equal.Click If strdx(2) = "0" Then Select Case calcount1 Case "+" output.Text = Str(Val(strdx(1) + Val(strdx(0

9、) Case "-" output.Text = Str(Val(strdx(1) - Val(strdx(0) Case "*" output.Text = Str(Val(strdx(1) * Val(strdx(0) Case "/" If strdx(0) = "0" Then output.Text = "error!" Else output.Text = Str(Val(strdx(1) / Val(strdx(0) End If End Select ElseIf calcoun

10、t2 = "*" Then strdx(0) = Str(Val(strdx(0) * Val(strdx(2) Select Case calcount1 Case "+" output.Text = Str(Val(strdx(1) + Val(strdx(0) Case "-" output.Text = Str(Val(strdx(1) - Val(strdx(0) Case "*" output.Text = Str(Val(strdx(1) * Val(strdx(0) Case "/&quo

11、t; If strdx(0) = "0" Then output.Text = "error!" Else output.Text = Str(Val(strdx(1) / Val(strdx(0) End If End Select Else : calcount2 = "/" strdx(0) = Str(Val(strdx(2) / Val(strdx(0) Select Case calcount1 Case "+" output.Text = Str(Val(strdx(1) + Val(strdx(0)

12、 Case "-" output.Text = Str(Val(strdx(1) - Val(strdx(0) Case "*" output.Text = Str(Val(strdx(1) * Val(strdx(0) Case "/" If strdx(0) = "0" Then output.Text = "error!" Else output.Text = Str(Val(strdx(1) / Val(strdx(0) End If End Select End If End Sub

13、Private Sub one_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles one.Click If strdx(0) = "0" Then strdx(0) = "1" output.Text = strdx(0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "1" output.Text = strdx(0) & &

14、quot;." Else strdx(0) = strdx(0) & "1" output.Text = strdx(0) End If End Sub Private Sub two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles two.Click If strdx(0) = "0" Then strdx(0) = "2" output.Text = strdx(0) & "." Els

15、eIf strvalue = False Then strdx(0) = strdx(0) & "2" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "2" output.Text = strdx(0) End If End Sub Private Sub three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles three.Click If s

16、trdx(0) = "0" Then strdx(0) = "3" output.Text = strdx(0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "3" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "3" output.Text = strdx(0) End If End Sub Private

17、Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click If calcount1 = "0" Then calcount1 = "+" strdx(1) = strdx(0) strdx(0) = "0" Else : Select Case calcount1 Case "+" strdx(1) = Str(Val(strdx(0) + Val(strdx(1) strdx(0) = &

18、quot;0" calcount1 = "+" Case "-" strdx(1) = Str(Val(strdx(1) - Val(strdx(0) strdx(0) = "0" calcount1 = "+" Case "*" strdx(1) = Str(Val(strdx(0) * Val(strdx(1) strdx(0) = "0" calcount1 = "+" Case "/" strdx(1) = Str(V

19、al(strdx(1) / Val(strdx(0) strdx(0) = "0" calcount1 = "+" End Select End If End Sub Private Sub subtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subtract.Click If calcount1 = "0" Then calcount1 = "-" strdx(1) = strdx(0) strdx(

20、0) = "0" Else : Select Case calcount1 Case "+" strdx(1) = Str(Val(strdx(0) + Val(strdx(1) strdx(0) = "0" calcount1 = "-" Case "-" strdx(1) = Str(Val(strdx(1) - Val(strdx(0) strdx(0) = "0" calcount1 = "-" Case "*" strdx(1

21、) = Str(Val(strdx(0) * Val(strdx(1) strdx(0) = "0" calcount1 = "-" Case "/" strdx(1) = Str(Val(strdx(1) / Val(strdx(0) strdx(0) = "0" calcount1 = "-" End Select End If End Sub Private Sub four_Click(ByVal sender As System.Object, ByVal e As System.Ev

22、entArgs) Handles four.Click If strdx(0) = "0" Then strdx(0) = "4" output.Text = strdx(0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "4" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "4" output.Text =

23、strdx(0) End If End Sub Private Sub five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles five.Click If strdx(0) = "0" Then strdx(0) = "5" output.Text = strdx(0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "5" outp

24、ut.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "5" output.Text = strdx(0) End If End Sub Private Sub six_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles six.Click If strdx(0) = "0" Then strdx(0) = "6" output.Text = strdx(

25、0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "6" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "6" output.Text = strdx(0) End If End Sub Private Sub multiply_Click(ByVal sender As System.Object, ByVal e As System.EventA

26、rgs) Handles multiply.Click If calcount1 = "0" Then calcount1 = "*" strdx(1) = strdx(0) strdx(0) = "0" Else : Select Case calcount1 Case "+" calcount2 = "*" strdx(2) = strdx(0) strdx(0) = "0" Case "-" calcount2 = "*" str

27、dx(2) = strdx(0) strdx(0) = "0" Case "*" strdx(1) = Str(Val(strdx(0) * Val(strdx(1) strdx(0) = "0" calcount1 = "*" Case "/" strdx(1) = Str(Val(strdx(1) / Val(strdx(0) strdx(0) = "0" calcount1 = "*" End Select End If End Sub Privat

28、e Sub divide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divide.Click If calcount1 = "0" Then calcount1 = "/" strdx(1) = strdx(0) strdx(0) = "0" Else : Select Case calcount1 Case "+" calcount2 = "/" strdx(2) = strdx(0) s

29、trdx(0) = "0" Case "-" calcount2 = "/" strdx(2) = strdx(0) strdx(0) = "0" Case "*" strdx(1) = Str(Val(strdx(0) * Val(strdx(1) strdx(0) = "0" calcount1 = "/" Case "/" strdx(1) = Str(Val(strdx(1) / Val(strdx(0) strdx(0) =

30、"0" calcount1 = "/" End Select End If End Sub Private Sub seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles seven.Click If strdx(0) = "0" Then strdx(0) = "7" output.Text = strdx(0) & "." ElseIf strvalue = False Then

31、strdx(0) = strdx(0) & "7" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "7" output.Text = strdx(0) End If End Sub Private Sub eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eight.Click If strdx(0) = "0" Th

32、en strdx(0) = "8" output.Text = strdx(0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "8" output.Text = strdx(0) & "." Else strdx(0) = strdx(0) & "8" output.Text = strdx(0) End If End Sub Private Sub nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nine.Click If strdx(0) = "0" Then strdx(0) = "9" output.Text = strdx(0) & "." ElseIf strvalue = False Then strdx(0) = strdx(0) & "9" output.Text = strdx(0) & "." Else st

温馨提示

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

评论

0/150

提交评论