湖南医药学院VB计算器课程设计题目: VB科学计算器院(系)别临床医学院专业临床医学班级本临一班学号 *************姓名夏铭锴指导教师李跃强二○一六年四月目录一、设计内容及要求二、设计原始资料三、设计完成后提交的文件和图表设计四、进程安排五、主要参考资料[摘要]用VB制作这个程序的简单计算器,它包括一个标准的计算器和一个科学计算器。
它可以实现简单的加减乘除四则运算,数字的平方、平方根,正弦、余弦、正切,倒数、指数函数、对数函数,角度、弧度、梯度的转换,以及各进制的相互转换。
而且它的功能还有退格,清除当前数据,清除所有数据,复制数据,粘贴数据。
在这个计算器的程序中,我用到了单行选择语句If…Then…Else…,块语句if…then…end if,If语句的嵌套,多条件选择语句Select Case,而且还用到了按钮、文本框、框架、单选按钮控件,菜单的设计。
在此报告中我重点叙述了计算机的各个功能及用法。
特别是进制间的转换和数字与运算符之间的联系。
虽然描述的不太完整,但我会尽力使用系统结构图,划分多个模块,让大家明白我设计的运算器的功能的。
[关键词]Visual Basic;计算器;对象;代码12三、设计完成后提交的文件和图表设计(要求2000字以上)1. 设计方案实现这个实用计算器,要考虑的主要是以下两个方面的内容:一、设置每个控件按钮的属性。
二、每组控件组都有自己的VB代码,由VB语言实现各个控件按钮的功能。
于是本设计就是以这两个个部分为核心内容展开。
根据设计要求该实用计算器能实现四则运算和部分科学计算法等按钮的控制,根据各组控件按钮源代码的不同,来实现按下不同的按键实现不同的计算过程或结果功能。
本设计大体由窗体、CommandButton、Textbox、Timer 四个模块构成。
其中Commandbutton作为按钮模块,Textbox作为显示模块,Timer作为显示或隐藏部分按键的模块。
Commandbutton按钮实现数字键和其他算法按键的功能;Textbox实现计算过程和结果的数字显示;Timerbox 实现当计算器只用到四则的简单运算时,窗体只显示四种运算的基本按键,当用到科学计算时,再在窗体中显示科学计算的控件按钮。
2.流程图、图纸⑴计算器如图3此计算器可以计算简单的加减乘除计算,还包括三角函数、乘方、阶乘、开方、对数等等的计算。
加有退出键,说明按钮等控件。
⑵总体设计框架四、进程安排(1)创建应用程序的界面。
(2)设置属性。
(3)编写代码。
(4)调试运行。
(5)保存工程及生成可执行文件。
4附页:设计原始资料Private Sub Command1_Click() '删除数字的最后一位If Label3.Caption <> "" ThenLabel3.Caption = Left(Label3.Caption, Len(Label3.Caption) - 1) Elsec = MsgBox("内容已为空!不可删除一位!", 49, "注意!")End IfEnd SubPrivate Sub Command10_Click() '输入数字6 Label3.Caption = Label3.Caption + Command10.CaptionEnd SubPrivate Sub Command11_Click()If Label3.Caption <> "" Then '输入符号*Label1.Caption = Label3.CaptionLabel2.Caption = Command11.CaptionLabel3.Caption = ""Elsec = MsgBox("请输入数据后输入符号!", 49, "注意!")End IfEnd Sub5Private Sub Command12_Click() '输入数字1Label3.Caption = Label3.Caption + Command12.CaptionEnd SubPrivate Sub Command13_Click() '输入数字2Label3.Caption = Label3.Caption + Command13.CaptionEnd SubPrivate Sub Command14_Click() '输入数字3Label3.Caption = Label3.Caption + Command14.CaptionEnd SubPrivate Sub Command15_Click() '输入符号—If Label2 <> "" ThenLabel3.Caption = -Val(Label3.Caption)ElseLabel1.Caption = Label3.CaptionLabel2.Caption = Command15.CaptionLabel3.Caption = ""End IfEnd SubPrivate Sub Command16_Click() '输入数字0Label3.Caption = Label3.Caption + Command16.CaptionEnd SubPrivate Sub Command17_Click() '输入小数点Label3.Caption = Label3.Caption + Command17.CaptionEnd SubPrivate Sub Command18_Click() '“=”按钮If Label1.Caption <> "" ThenIf Label2.Caption = "*" Then '计算乘法Label3.Caption = Label1.Caption & "*" & Label3.Caption & "=" & Val(Label1.Caption) * Val(Label3.Caption)ElseIf Label2.Caption = "/" Then '计算除法If Val(Label3.Caption) <> 0 ThenLabel3.Caption = Label1.Caption & "/" & Label3.Caption & "=" & Val(Label1.Caption) / Val(Label3.Caption)Elsec = MsgBox("除数不能为0!请重新输入!", 49, "注意!")End IfElseIf Label2.Caption = "-" Then '计算减法Label3.Caption = Label1.Caption & "-" & Label3.Caption & "=" & Val(Label1.Caption) - Val(Label3.Caption)ElseIf Label2.Caption = "+" Then '计算加法Label3.Caption = Label1.Caption & "+" & Label3.Caption & "=" & Val(Label1.Caption) + Val(Label3.Caption)ElseIf Label2.Caption = "mod" Then '进行取余运算6If Label3.Caption = 0 Thenc = MsgBox("除数不能为0!" + Chr(13) + Chr(10) + "请重新输入!", 49, "提示!")ElseLabel3.Caption = Label1.Caption & " mod " & Label3.Caption & " = " & Val(Label1.Caption) Mod Val(Label3.Caption)End IfElseIf Label2.Caption = "x^y" Then '计算x^yLabel3.Caption = Label1.Caption & "^" & Label3.Caption & "=" & Val(Label1.Caption) ^ Val(Label3.Caption)End IfElseIf Label2.Caption = "-" Then '如果输入数字前输入“-”则按负数处理Label3.Caption = -Val(Label3.Caption)End IfEnd IfLabel1.Caption = ""Label2.Caption = ""Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command19_Click() '输入符号+If Label3.Caption <> "" ThenLabel1.Caption = Label3.CaptionLabel2.Caption = Command19.CaptionLabel3.Caption = ""Elsec = MsgBox("请输入数据后输入符号!", 49, "注意!")End IfEnd SubPrivate Sub Command2_Click()Label3.Caption = "" '清空Label2.Caption = ""Label1.Caption = ""End SubPrivate Sub Command20_Click()s = 1 '求阶乘n!For i = 1 To Val(Label3.Caption)s = s * iNextLabel3.Caption = Label3.Caption + "! =" & sOpen App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.Caption7Print #1,Close #1End SubPrivate Sub Command21_Click() '取整运算fixLabel3.Caption = "Fix(" & Label3.Caption & ")=" & Fix(Val(Label3.Caption))Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command22_Click() '取倒数If Val(Label3.Caption) <> 0 ThenLabel3.Caption = "1/" & Label3.Caption & "=" & 1 / Val(Label3.Caption)Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1Elsec = MsgBox("除数不能为0!" + Chr(13) + Chr(10) + "请重新输入!", 49, "注意!")End IfEnd SubPrivate Sub Command23_Click() '输入符号modLabel1.Caption = Label3.CaptionLabel2.Caption = Command23.CaptionLabel3.Caption = ""End SubPrivate Sub Command24_Click() '计算正切值tanLabel3.Caption = "tan(" & Label3.Caption & ")=" & Tan(Val(Label3.Caption) / 57.2958)Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command25_Click()If Val(Label3.Caption) > 0 Then '计算对数lnLabel3.Caption = "ln(" & Label3.Caption & ")=" & Log(Val(Label3.Caption))Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1Elsec = MsgBox("对数值应大于0,!" + Chr(13) + Chr(10) + "请重新输入!", 49, "注意!")End If8End SubPrivate Sub Command26_Click() '计算余弦值tanLabel3.Caption = "cos(" & Label3.Caption & ")=" & Cos(Val(Label3.Caption) / 57.2958)Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command27_Click() '计算e 的x 次方Label3.Caption = "Exp(" & Label3.Caption & ")=" & 2.71818 ^ Val(Label3.Caption)Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command28_Click() '计算正弦值Label3.Caption = "sin(" & Label3.Caption & ")=" & Sin(Val(Label3.Caption) / 57.2958)Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command29_Click() '计算不大于X的最大整数Label3.Caption = "Int(" & Label3.Caption & ")=" & Int(Val(Label3.Caption))Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command3_Click()End 'OFF按钮End SubPrivate Sub Command30_Click()If Val(Label3.Caption) >= 0 Then '开平方Label3.Caption = "sqr(" & Label3.Caption & ")=" & Sqr(Val(Label3.Caption))Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1Else9c = MsgBox("被开方数不能为负数!" + Chr(13) + Chr(10) + "请重新输入!", 49, "注意!")End IfEnd SubPrivate Sub Command31_Click() '输入X^YLabel1.Caption = Label3.CaptionLabel2.Caption = Command31.CaptionLabel3.Caption = ""End SubPrivate Sub Command32_Click() '求反正切值Label3.Caption = "tan-1(" & Label3.Caption & ")=" & Atn(Val(Label3.Caption)) * 57.2958Open App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1End SubPrivate Sub Command33_Click()a = Val(Label3.Caption) '求反余弦值If a > -1 And a < 1 ThenFor i = 0 To 360 Step 0.01If Abs(Cos(i / 57) - a) <= 0.001 Thend = iLabel3.Caption = "cos-1(" & Label3.Caption & ")= " & dExit ForEnd IfNextOpen App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1Elsec = MsgBox("余弦值范围为(-1,1)," + Chr(13) + Chr(10) + "请重新输入!", 49, "注意!")End IfEnd SubPrivate Sub Command34_Click()a = Val(Label3.Caption) '求反正弦值If a >= -1 And a <= 1 ThenFor i = 0 To 360 Step 0.01If Abs(Sin(i / 57) - a) <= 0.001 Thend = iLabel3.Caption = "sin-1(" & Label3.Caption & ")= " & dExit ForEnd IfNextOpen App.Path & "\记录" For Append As #1 '保存记录Print #1, "科学型计算器" & " "; Date & " "; Time()Print #1, Label3.CaptionPrint #1,Close #1Elsec = MsgBox("正弦值范围为(-1,1)," + Chr(13) + Chr(10) + "请重新输入!", 49, "注意!")End IfEnd SubPrivate Sub Command35_Click() '说明c = MsgBox("1.若需输入负号,如果是第一个数,请按“-”后按数字再按“=”,如果是第二个数,请按数字后按“-”。