vb2010实验报告-计算器的制作与实现
更新时间:2024-07-01 20:19:01 阅读量: 综合文库 文档下载
- vb2010教程推荐度:
- 相关推荐
软件开发环境与工具
实验报告
实验一
实验题目: 计算器的制作与实现 实验类型: 验证 实验地点: 软件实验室一 指导教师: 专业班级: 计算机科学与技术系班 姓 名:
20年10月25日
一、实验目的:
1、熟悉VB.NET程序开发环境,了解VB.NET应用程序设计的基本框架结构。 2、掌握Windows Form的事件处理机制,以及如何在运行期创建控件。 3、初步掌握VB.NET的基本编程方法和技巧。 二、实验内容:
设计一个简单的计算器程序,使之能够实现加、减、乘、除等基本的四则运算。 三、实验设计思路:
先模拟地设计出计算器面板,包含各类按钮和结果输出框,然后写出各个触发事件,包含数字事件、运算符号事件、等号事件等,之后再写各类运算函数,包括加法、减法、乘法和除法,最后于主函数中调用各功能及运算。 四、实验步骤: 1、打开Microsoft Visual Studio 2010,点击“新建项目”,在弹出的对话框中选择“Visual Basic/ Windows”项目类型,“模板”选择“Windows窗体应用程序”,在名称处将默认名WindowsApplication1改为“简易计算器”,然后指定该应用程序的保存路径,点击“确定”,进入窗体设计界面。
2、调整好窗体的大小后,将鼠标移到左侧“工具箱”位置,自动弹出“工具箱”窗口,选择其中的“TextBox”控件对象并将其拖拽到窗体中,调整大小并将其拖动到适当位置,在属性窗口中选定属性名“(Name)”,在右列中将其属性值设为“output”,用于显示数据。 3、用同样的方法向窗体中添加19个Button控件,单击“Button1”控件,同样在属性窗口中选定属性名“(Name)”,在右列中将其属性值设为“zero”,并在属性窗口中选定属性名“Text”,在右列中将其属性值设为“0”。用同样的方法依次将其他Button控件的“(Name)”属性值分别设为“point”、“AllClean”、“equal”、“one”、“two”、“three”、“add”、“subtract”、“four”、“five”、“six”、“multiply”、“divide”、“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 = {\, \, \} '声明一个字符串,用以存取数值 Dim calcount1 As String = \ Dim calcount2 As String = \ 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) = \ Then
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(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 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) = \ strdx(1) = \ strdx(2) = \ calcount1 = \ calcount2 = \ strvalue = False output.Text = \ End Sub
Private Sub equal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equal.Click If strdx(2) = \ Then 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 \
If strdx(0) = \ Then output.Text = \ Else
output.Text = Str(Val(strdx(1)) / Val(strdx(0))) End If End Select
ElseIf calcount2 = \ 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 \
If strdx(0) = \ Then output.Text = \ 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))) Case \
output.Text = Str(Val(strdx(1)) - Val(strdx(0))) Case \
output.Text = Str(Val(strdx(1)) * Val(strdx(0))) Case \
If strdx(0) = \ Then output.Text = \ Else
output.Text = Str(Val(strdx(1)) / Val(strdx(0))) End If End Select End If End Sub
Private Sub one_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles one.Click
If strdx(0) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ 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) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ 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 strdx(0) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ output.Text = strdx(0) End If End Sub
Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click If calcount1 = \ Then calcount1 = \
strdx(1) = strdx(0) strdx(0) = \
Else : Select Case calcount1 Case \
strdx(1) = Str(Val(strdx(0)) + Val(strdx(1))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(1)) - Val(strdx(0))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(0)) * Val(strdx(1))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(1)) / Val(strdx(0))) strdx(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 = \ Then calcount1 = \ strdx(1) = strdx(0) strdx(0) = \
Else : Select Case calcount1 Case \
strdx(1) = Str(Val(strdx(0)) + Val(strdx(1))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(1)) - Val(strdx(0))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(0)) * Val(strdx(1))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(1)) / Val(strdx(0)))
strdx(0) = \ calcount1 = \ End Select End If End Sub
Private Sub four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles four.Click If strdx(0) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ output.Text = 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) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ 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) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \
output.Text = strdx(0) End If End Sub
Private Sub multiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multiply.Click If calcount1 = \ Then calcount1 = \ strdx(1) = strdx(0) strdx(0) = \
Else : Select Case calcount1 Case \
calcount2 = \ strdx(2) = strdx(0) strdx(0) = \ Case \
calcount2 = \ strdx(2) = strdx(0) strdx(0) = \ Case \
strdx(1) = Str(Val(strdx(0)) * Val(strdx(1))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(1)) / Val(strdx(0))) strdx(0) = \ calcount1 = \ End Select End If End Sub
Private Sub divide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divide.Click If calcount1 = \ Then calcount1 = \ strdx(1) = strdx(0) strdx(0) = \
Else : Select Case calcount1 Case \
calcount2 = \ strdx(2) = strdx(0) strdx(0) = \ Case \
calcount2 = \
strdx(2) = strdx(0) strdx(0) = \ Case \
strdx(1) = Str(Val(strdx(0)) * Val(strdx(1))) strdx(0) = \ calcount1 = \ Case \
strdx(1) = Str(Val(strdx(1)) / Val(strdx(0))) strdx(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) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ 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) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ 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) = \ Then strdx(0) = \
output.Text = strdx(0) & \ ElseIf strvalue = False Then strdx(0) = strdx(0) & \ output.Text = strdx(0) & \ Else
strdx(0) = strdx(0) & \ output.Text = strdx(0) End If End Sub
Private Sub kai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kai.Click output.Text = \ End Sub
Private Sub guan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guan.Click Me.Close() End Sub
Private Sub output_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles output.TextChanged End Sub End Class
五、实验结果及截图:
1、单击工具栏中的“启动调试(F5)”按钮,运行程序。 2、单击工具栏中的“on”按钮,文本框显示数据“0.”,如下图所示:
3、实现加法运算(27+31=58):输入数据“27”,点击“+”按钮,再输入数据“31”,按下“=”按钮,文本框显示运算结果“58”,具体过程如下图所示:
4、点击“AC”按钮,实现文本框清零,如下图所示:
5、实现减法运算(47-24=23):依次点击“47”、“-”、“24”、“=”,文本框显示运算结果,如下图所示:
6、点击“AC”,实现乘法运算(27*18=486):依次点击“27”、“*”、“18”、“=”,文本框显示运算结果,如下图所示:
7、点击“AC”,实现除法运算(47/5):依次点击“47”、“/”、“5”、“=”,文本框显示运算结果,如下图所示:
8、点击“off”按钮,程序结束运行,窗口被关闭。 六、实验总结:
通过本次实验,对VB.NET程序开发环境有了进一步的认识,了解了VB.NET应用程序设计的基本框架结构,掌握了Windows Form的事件处理机制以及VB.NET的基本编程方法和技巧,能够对Windows窗体和常用控件进行简单的设计处理,进一步熟悉了VB.NET应用程序的各种运算符、表达式和程序控制结构,基本实现了简单计算器的运算功能。虽然实验还有诸多不完善的地方,如计算结果不能与表达式同时显示,但是我会继续努力,争取掌握更多VB.NET程序设计方面的知识,进一步完善本次实验。
正在阅读:
vb2010实验报告-计算器的制作与实现07-01
2015年5月人力资源管理师二级第三章课后习题答案(最新版) - 图03-29
网络优化常见问题及其相关解决思路05-09
继电保护竞赛大题之--分析题汇总第1套06-13
母亲健康快车五年工作总结范文04-09
鲁玉金开题报告04-21
《雷锋档案》电影观感02-23
冀教版五年级上册英语第四单元07-20
川豪工装事业部运营建议书05-13
论 违 约 责 任02-29
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 计算器
- 实验
- 实现
- 报告
- 制作
- vb2010
- 节水节电,低碳有我
- 新人教版山东小学数学四年级上册单元测试题_全册精品
- 水工钢筋混凝土课程设计 - 图文
- 部编版二年级上册语文识字表生字注音练习
- 第三册语文扩词
- 江苏某办公楼装饰施工组织设计方案
- 2011年社团联外联部上半学年工作计划
- 九年级历史下册第16课世界经济的“全球化”教案新人教版
- 安全生产管理人员复训试题(2017最新)420道
- 运维工区新进大学生智能站培训 - 图文
- 初高中衔接教材含答案
- 《激光原理与技术》习题一
- 因子分析报告
- 18秋季东财《中国对外贸易X》在线作业一(随机)1
- 八路抢答器套件讲义V1
- 过氧化物酶体功能每日一练(2015.11.13)
- Mapinfo网络优化中的使用说明(刘斌版)
- 2017—2018年新苏教版一年级数学下册认识100以内的数(精品教案
- 信息技术基础知识汇总
- 2016年核心素养下的小学数学 心得体会