在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 07:42:31
在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要在VB中计算器的代码

在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要
在VB中计算器的代码(要求0到9的加减乘除运算)
只要0到9的加减乘除还有等于号其他都不需要

在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要
Dim Num1 As Double
Dim Num2 As Double
Dim Equal As Double
Dim M As Double
Dim Equal2 As Integer
Dim StrNum1 As String
Dim StrNum2 As String
Dim FirstPoint As Boolean
Dim FirstNum As Boolean
Private Sub Command1_Click(Index As Integer) '数字输入
Select Case Index
Case 0 To 9
StrNum1 = LTrim(StrNum1) + LTrim(Str(Index))
Do While Left(LTrim(StrNum1), 1) = "0" '去掉高位数字0
StrNum1 = Mid(StrNum1, 2)
Loop
If Left(LTrim(StrNum1), 1) = "." Then StrNum1 = "0" + LTrim(StrNum1)
Text1.Text = StrNum1 '数字显示
Case 10
If FirstPoint Then '小数点的输入
StrNum1 = LTrim(StrNum1) + LTrim(".")
Do While Left(LTrim(StrNum1), 1) = "0" '去掉高位数字0
StrNum1 = Mid(StrNum1, 2)
Loop
If Left(LTrim(StrNum1), 1) = "." Then StrNum1 = "0" + LTrim(StrNum1)
Text1.Text = StrNum1 '数字显示
FirstPoint = False
Text1.Text = StrNum1
End If
Case 11
StrNum1 = Text1.Text '退格
If Len(StrNum1) > 0 Then
StrNum1 = Left(StrNum1, Len(StrNum1) - 1) '每一次退格,从字符串后面去掉一个字符
Text1.Text = StrNum1
Else
Text1.Text = "0.0"
End If
If InStr(StrNum1, ".") = 0 Then FirstPoint = True '若字符串中没有小数点,把小数点开关打开
Case 12 '清零
StrNum1 = ""
StrNum2 = ""
Text1.Text = "0.0"
aa = ""
Equal = 0
Num1 = 0
Num2 = 0
FirstPoint = True '小数点开关
FirstNum = True '第一个数开关
Case 13 '正负符号
If Val(StrNum1) > 0 Then
StrNum1 = "-" + LTrim(StrNum1)
Else
StrNum1 = Abs(Val(StrNum1))
End If
Text1.Text = StrNum1
Case 14 '电源开关
End
End Select
End Sub
Private Sub Command2_Click(Index As Integer) '+-*/运算
Equal2 = Index '=号开关
If FirstNum Then '存第一个数,其中FirstNum为开关
StrNum2 = StrNum1
StrNum1 = ""
FirstNum = False
FirstPoint = True '小数点开,以便输入第二个数
Else '若不是第一个数进入下面的+-*/运算
Select Case Index
Case 0 '0为加法
Num1 = Val(StrNum2) 'Num1存第一个数
Num2 = Val(StrNum1) 'Num2存第二个数
Equal = Num1 + Num2 'Equal存结果
StrNum2 = Str(Equal) 'StrNum2返回结果,以便下次让Num1存结果
StrNum1 = "" 'StrNum1清空,以便下次数字输入
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa '显示结果
FirstPoint = True '小数点开
Case 1 '1为减法
Num1 = Val(StrNum2)
Num2 = Val(StrNum1)
Equal = Num1 - Num2
StrNum2 = Str(Equal)
StrNum1 = ""
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
FirstPoint = True
Case 2 '为乖法
Num1 = Val(StrNum2)
If StrNum1 = "" Then '便于+-*/之间切换
Num2 = 1
Else
Num2 = Val(StrNum1)
End If
Equal = Num1 * Num2
StrNum2 = Str(Equal)
StrNum1 = ""
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
FirstPoint = True
Case 3 '3为除法
Num1 = Val(StrNum2) 'Num1存第一个数
If StrNum1 = "" Then
Num2 = 1
Else
Num2 = Val(StrNum1)
End If
Equal = Num1 / Num2
StrNum2 = Str(Equal) 'Num2存第二个数
StrNum1 = ""
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
FirstPoint = True
End Select
End If
End Sub
Private Sub Command3_Click() '=号运算
FirstNum = True '第一个数关,关掉连继+-*/
Select Case Equal2 'Equal2为=号按键判断+-*/哪种运算
Case 0 '+运算
If StrNum2 = "" Then
Num1 = Equal
Else
Num1 = Val(StrNum2)
End If
Num2 = Val(Text1.Text)
Equal = Num1 + Num2
StrNum1 = "" '返回结果
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa '显示结果
FirstPoint = True '小数点开
Case 1 '-运算
If StrNum2 = "" Then
Num1 = Equal
Else
Num1 = Val(StrNum2)
End If
Num2 = Val(Text1.Text)
Equal = Num1 - Num2
StrNum1 = ""
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
FirstPoint = True
Case 2 '*运算
If StrNum2 = "" Then
Num1 = Equal
Else
Num1 = Val(StrNum2)
End If
If StrNum1 = "" Then
Num2 = 1
Else
Num2 = Val(Text1.Text)
End If
Equal = Num1 * Num2
StrNum1 = ""
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
FirstPoint = True
Case 3 '/运算
If StrNum2 = "" Then
Num1 = Equal
Else
Num1 = Val(StrNum2)
End If
If StrNum1 = "" Then
Num2 = 1
Else
Num2 = Val(Text1.Text)
End If
Equal = Num1 / Num2
StrNum1 = ""
aa = Str(Equal)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
FirstPoint = True
End Select
End Sub
Private Sub Command4_Click() '开方运算
aa = Val(Text1.Text)
StrNum1 = ""
If aa >= 0 Then
aa = Str(Sqr(aa))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
Else
MsgBox "被开方数少于零"
End If
End Sub
Private Sub Command7_Click() '倒数运算
aa = Val(Text1.Text)
StrNum1 = ""
aa = Str(1 / aa)
If Left(LTrim(aa), 1) = "-" And Left(LTrim(aa), 2) = "-." Then aa = "-0" + LTrim(Abs(Equal))
If Left(LTrim(aa), 1) = "." Then aa = "0" + LTrim(aa)
Text1.Text = aa
End Sub
Private Sub Command8_Click(Index As Integer) '存贮器操作
Select Case Index
Case 0 'MC,存贮器清零
Text2.Text = ""
M = 0
Case 1 'MR,显示存贮器内容

在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要 如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能 用0~9按钮实现 类似WINDOWS系统自带的计算器 最好带图最好有声明 代码太多 看着晃~ VB里如何做个可以计算sin和cos的计算器? 求代码在文本框中输入一个弧度 可以在标签里显示出sin的值 不知道代码怎么编 VB随机生成0到1000的数 为什么是乘1000生成0~1000的随机整数,代码是:int(rnd*1000)为什么不是*1001啊? 求有数字按键的简单vb计算器代码,插入到哪才能用呢 vb 计算器中按等号再按数字键时的问题我用vb编写了一个计算器程序,数字输入的代码是这样的Text1.Text = Text1.Text & 7,可在按下=号键后,希望再按数字键时是重新输入,而不是在后面添加,如何编 已知两点坐标,在vb中怎样计算两点连线与水平线的角度?求公式代码我需要在VB中的代码啊 vb编计算器中连续运算的代码,以及按等号后得出的数如何继续运算?编得好的加分 怎么在VB中求和我是想编一个简单计算器,编到求和这块不太会了,下面是我写的代码,麻烦帮我想一下Sub op()T1.Enabled = TrueT1.Visible = TrueT1.SetFocusEnd SubSub oi()T1.Enabled = FalseT1.Visible = FalseEnd SubPrivate 求写vb代码,要求:在100~200之间的数中找出同时满足除3余2,除5余3和除7...求写vb代码,要求:在100~200之间的数中找出同时满足除3余2,除5余3和除7余2的所有整数! vb算式四舍五入在vb缩写的代码中有一个算式:(ProgressBar1.Value / Text2.Text) * 10,怎样让这个算式计算的结果只保留到整数呢?如果是小数就自动四舍五入. VB中,log(X)如何计算,代码是什么,其中X是大于0的自然数 x^3-x-1=0在vb中用牛顿迭代法求在1.5附近的跟,精确到0.5*10^-3 求代码. 用VB程序设计计算器用VB编程序设计一个简易的计算器.实验要求:1.设计合适的运行界面并编写相应的事件代码.2.要求用标签显示运算数据及运算结果.初始状态显示0.3.要求用命令按钮输入运 VB:产生20个30到50之间的随机数,并以每行4个进行排列.要求代码尽可能简洁易懂, 用VB在1-100中产生10个随机整数,按从小到大的顺序排列 如题..求代码 VB随机产生3位数的代码 我想在用VB作一个科学计算器,怎样实现sin.cos.tan等功能代码怎么写VB