首页 技术 正文
技术 2022年11月8日
0 收藏 756 点赞 1,443 浏览 1354 个字

使用visual basic编写。

绘制如下的按钮界面:

然后代码如下:

Dim a, temp, ans As Integer
Dim op As StringSub showans()
Text1.Text = a
End SubSub clearans()
Text1.Text = " "
End SubPrivate Sub Command1_Click()
'按钮1a = a * 10 + 1
Call showans
End SubPrivate Sub Command10_Click()
'按钮0
a = a * 10
Call showansEnd SubPrivate Sub Command11_Click()
'按钮=
If op = "+" Then
a = temp + a
ElseIf op = "-" Then
a = temp - a
ElseIf op = "*" Then
a = temp * a
ElseIf op = "/" Then
If a <> 0 Then
a = temp / a
Else
MsgBox ("Divisor can't be zero!")
End If
End If
Call showans
temp = a
End SubPrivate Sub Command12_Click()
'按钮CE
a = 0
Call showans
End SubPrivate Sub Command13_Click()
'按钮+
temp = a
a = 0
op = "+"
Call clearans
End SubPrivate Sub Command14_Click()
'按钮-
temp = a
a = 0
op = "-"
Call clearans
End SubPrivate Sub Command15_Click()
'按钮*
temp = a
a = 0
op = "*"
Call clearans
End SubPrivate Sub Command16_Click()
'按钮/
temp = a
a = 0
op = "/"
Call clearans
End SubPrivate Sub Command2_Click()
'按钮2
a = a * 10 + 2
Call showans
End SubPrivate Sub Command3_Click()
'按钮3
a = a * 10 + 3
Call showans
End SubPrivate Sub Command4_Click()
'按钮4
a = a * 10 + 4
Call showans
End SubPrivate Sub Command5_Click()
'按钮5
a = a * 10 + 5
Call showans
End SubPrivate Sub Command6_Click()
'按钮6
a = a * 10 + 6
Call showans
End SubPrivate Sub Command7_Click()
'按钮7
a = a * 10 + 7
Call showans
End SubPrivate Sub Command8_Click()
'按钮8
a = a * 10 + 8
Call showans
End SubPrivate Sub Command9_Click()
'按钮9
a = a * 10 + 9
Call showans
End SubPrivate Sub Form_Load()
a = 0
temp = 0
ans = 0End Sub

解释说明:

a表示当前的结果,temp表示上一个运算数

例如:

1+2,依次按下1,+,2,按下加号后temp=1,a=2,执行=键的运算时temp+a就是1+2=3

因为之后还要使用3进行计算,所以,需要将temp=a,这时再输入+2,就是3+2=5

效果展示:

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902