欢迎光临
我们一直在努力

用vb编一个计算器,需要用到数组,看看下面的代码,欢迎来找碴!-.NET教程,VB.Net语言

建站超值云服务器,限时71元/月

这是我的代码,请帮我看看哪有问题:(我是要用数组作个计算器)

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用vb编一个计算器,需要用到数组,看看下面的代码,欢迎来找碴!-.NET教程,VB.Net语言
分享到: 更多 (0)

相关推荐

  • 暂无文章