用vb编一个计算器,需要用到数组,看看下面的代码,欢迎来找碴!
2004-10-05 16:58
806 查看
这是我的代码,请帮我看看哪有问题:(我是要用数组作个计算器)
Option Explicit
Dim shu1 As Double, shu2 As Double '先后输入的两个数
Dim result As Double '做了运算的结果
Dim process, process0, process1, process2, process3, process4 As Variant '保存数1与各个运算符的过程
Dim judge As Variant '判断按了那个运算符
Private Sub Command1_Click(Index As Integer) '0-9数字键
Text1.Text = Text1.Text & Index
Text1.SetFocus
End Sub
Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer) '阻止键盘输入,不过不知为什么没有用
KeyAscii = 0
End Sub
Private Sub Command2_Click(Index As Integer) ' "."键
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command3_Click() '退格键
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command4_Click() '清除键
Text1.Text = ""
End Sub
Private Sub Command5_Click(Index As Integer) '做运算,总觉得逻辑上哪有问题
shu1 = Val(Text1.Text)
process = shu1
Text1.Text = ""
If judge = Command5(0) Then
process0 = shu1 + Command(0)
ElseIf judge = Command5(1) Then
process1 = shu1 + Command5(1)
ElseIf judge = Command5(2) Then
process2 = shu1 + Command(2)
ElseIf judge = Command5(3) Then
process3 = shu1 + Command5(3)
End If
shu2 = Val(Text1.Text)
End Sub
Private Sub Command6_Click() '等号
result = process + shu2
Text1.Text = result
If process0 Then
result = shu1 + shu2
ElseIf process1 Then
result = shu1 - shu2
ElseIf process2 Then
result = shu1 * shu2
ElseIf process3 Then
result = shu1 / shu2
End If
End Sub
Private Sub Text1_Change()
If judge = False Then
shu2 = Val(Text1.Text)
End If
Text1.SetFocus
End Sub
Option Explicit
Dim shu1 As Double, shu2 As Double '先后输入的两个数
Dim result As Double '做了运算的结果
Dim process, process0, process1, process2, process3, process4 As Variant '保存数1与各个运算符的过程
Dim judge As Variant '判断按了那个运算符
Private Sub Command1_Click(Index As Integer) '0-9数字键
Text1.Text = Text1.Text & Index
Text1.SetFocus
End Sub
Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer) '阻止键盘输入,不过不知为什么没有用
KeyAscii = 0
End Sub
Private Sub Command2_Click(Index As Integer) ' "."键
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command3_Click() '退格键
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command4_Click() '清除键
Text1.Text = ""
End Sub
Private Sub Command5_Click(Index As Integer) '做运算,总觉得逻辑上哪有问题
shu1 = Val(Text1.Text)
process = shu1
Text1.Text = ""
If judge = Command5(0) Then
process0 = shu1 + Command(0)
ElseIf judge = Command5(1) Then
process1 = shu1 + Command5(1)
ElseIf judge = Command5(2) Then
process2 = shu1 + Command(2)
ElseIf judge = Command5(3) Then
process3 = shu1 + Command5(3)
End If
shu2 = Val(Text1.Text)
End Sub
Private Sub Command6_Click() '等号
result = process + shu2
Text1.Text = result
If process0 Then
result = shu1 + shu2
ElseIf process1 Then
result = shu1 - shu2
ElseIf process2 Then
result = shu1 * shu2
ElseIf process3 Then
result = shu1 / shu2
End If
End Sub
Private Sub Text1_Change()
If judge = False Then
shu2 = Val(Text1.Text)
End If
Text1.SetFocus
End Sub
相关文章推荐
- git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0
- 曲线解决CMFCPropertyGridCtrl掩码的bug2009年12月30日 星期三 下午 01:24CMFCPropertyGridCtrl这个控件当用到掩码时,会有问题.解决办法用其他掩码替代.下面是一个IP掩码处理方法.代码如下
- 一个计算器的代码,欢迎大家点评
- 一个计算器的代码,欢迎大家点评。
- 一个数组中只有两个数是不同的,其他数字是成对出现的,下面代码可将该数组中不同的两数字找出并输出
- 加载设计器时遇到一个或多个错误。这些错误在下面列出。一些错误可通过重新生成项目来修复,而另一些错误则需要更改代码。
- 一个数组中只有两个数是不同的,其他数字是成对出现的,下面代码可将该数组中不同的两数字找出并输出
- 现在正在写一个搜索功能代码 需要用到正则表达式
- 最近给财务做了一个接口,要求gridview里同列数值相同时到Excel不显示.下面来看看主要的代码
- 一个计算器的代码,欢迎大家点评
- [VB.NET]看看下面的代码,怎么没有错误提示呀!!!!!!
- 设计算法并写出代码移除字符串中重复的字符,不能使用额外的缓存空间。注意: 可以使用额外的一个或两个变量,但不允许额外再开一个数组拷贝。
- C语言typedef定义结构体数组,下面这段代码是什么意思?
- 看看一个朋友写的代码,大家发表发表意见,比较简单的代码
- Javascript中克隆一个数组的实现代码
- 一个简单的动态编译器,支持C#和VB.NET。当你想测试一些简单的代码的时候可以使用。
- 写一个“标准”宏MIN,这个宏输入两个参数并返回较小的一个。另外,当你写下面的代码时会发生什么事?least = MIN(*p++, b)
- php xml 解析成数组(目前仅支持5级,需要照样添加代码就行)
- 简单封装一个AlertDialog,调用只需要两行代码