用vb編一個(gè)計(jì)算器,需要用到數(shù)組,看看下面的代碼,歡迎來找碴!
2024-07-21 02:21:06
供稿:網(wǎng)友
 
這是我的代碼,請(qǐng)幫我看看哪有問題:(我是要用數(shù)組作個(gè)計(jì)算器)
 option explicit
dim shu1 as double, shu2 as double '先后輸入的兩個(gè)數(shù)
dim result as double '做了運(yùn)算的結(jié)果
dim process, process0, process1, process2, process3, process4 as variant '保存數(shù)1與各個(gè)運(yùn)算符的過程
dim judge as variant '判斷按了那個(gè)運(yùn)算符
private sub command1_click(index as integer) '0-9數(shù)字鍵
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) '做運(yùn)算,總覺得邏輯上哪有問題
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() '等號(hào)
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