1樓:沙慧月
我已發**
private sub command1_click(index as integer)
if index = 16 then
text1 = mid(text1, 1, len(text1) - 1)
elseif index = 15 then
text1.text = calcstr(text1.text)
else
text1 = text1 & command1(index).caption
end if
end sub
function calcstr(strnum as string) as double
dim x as integer
dim y as integer
for i = 1 to len(text1.text)
if isnumeric(mid(strnum, i, 1)) = false then
x = left(strnum, i - 1)
y = mid(strnum, i + 1)
z = mid(strnum, i, 1)
exit for
end if
next
select case z
case "+"
calcstr = x + y
case "-"
calcstr = x - y
case "*"
calcstr = x * y
case "/"
if y = 0 then
msgbox "除數應不為0"
else
calcstr = x / y
end if
end select
end function
2樓:吹花
想跟calc一樣太難了,微軟不是吃閒飯的,它的科學型選項開啟支援各種進位制,角度,梯度,一大堆函式選項等,業餘人員開發四則運算就可以了,不能苛求。
你做的時候用控制元件陣列會容易些
用vb製作一個像windows計算器一樣的源**
3樓:匿名使用者
我做了一個簡單型的,為簡化**用到了空間陣列,希望你能看懂!
'程式:vb 簡單計算器
'日期:2023年1月16日
'部落格:447201162.blog.163.com
dim xs
dim xsf
dim shu1
dim cx
dim xsd
dim m
dim dy
dim shu2
private sub command1_click(index as integer)
if xs = 1 then
xs = 0
text1 = index
cx = 1
xsd = 0
else
text1 = text1 & index
end if
if dy = 1 then xsf = 0
end sub
private sub command10_click()
if dy = 0 then shu2 = text1
if xsf = 1 then
text1 = val(text1) + val(shu1)
xs = 1
end if
if xsf = 2 then
if dy = 0 then text1 = val(shu1) - val(text1) else text1 = val(text1) - val(shu1)
xs = 1
end if
if xsf = 3 then
text1 = val(text1) * val(shu1)
xs = 1
end if
if xsf = 4 then
if val(text1) = "0" then
text1 = "除數不能為零。"
else
if dy = 0 then text1 = val(shu1) / val(text1) else text1 = val(text1) / val(shu1)
end if
xs = 1
end if
if dy = 0 then shu1 = shu2
dy = 1
cx = 0
xs = 1
end sub
private sub command11_click()
m = m + val(text1)
xs = 1
if m <> 0 then label1.caption = "m" else label1.caption = ""
end sub
private sub command12_click()
m = m - val(text1)
xs = 1
if m <> 0 then label1.caption = "m" else label1.caption = ""
end sub
private sub command13_click()
text1 = m
cx = 1
xs = 1
end sub
private sub command14_click()
label1.caption = ""
m = 0
end sub
private sub command15_click()
text1 = 3.14159265358979
xs = 0
end sub
private sub command2_click()
if dy = 1 then
text1 = "0."
xsd = 1
end if
if xsd <> 1 then
text1 = text1 & "."
xsd = 1
end if
if text1 = "." then text1 = "0."
xs = 0
end sub
private sub command3_click()
text1 = 0 - text1
end sub
private sub command4_click()
text1 = ""
xs = 0
xsf = 0
shu1 = 0
cx = 0
xsd = 0
dy = 0
shu2 = 0
end sub
private sub command5_click()
text1 = ""
xs = 0
xsf = 0
shu1 = 0
cx = 0
xsd = 0
dy = 0
shu2 = 0
end sub
private sub command6_click(index as integer)
if xsf <> 1 and xsf <> 2 and xsf <> 3 and xsf <> 4 then
shu1 = text1
goto 1
end if
if dy = 1 then goto 2
if cx = 0 then goto 1
if index + 1 = 1 then
text1 = val(text1) + val(shu1)
xs = 1
end if
if index + 1 = 2 then
text1 = val(shu1) - val(text1)
xs = 1
end if
if index + 1 = 3 then
text1 = val(text1) * val(shu1)
xs = 1
end if
if index + 1 = 4 then
text1 = val(shu1) / val(text1)
xs = 1
end if
shu1 = text1
cx = 0
exit sub
2:shu1 = text1
1:dy = 0
xs = 1
xsf = index + 1
end sub
private sub command7_click()
text1 = sqr(text1)
xs = 1
end sub
private sub command8_click()
text1 = val(text1) * val(text1)
xs = 1
end sub
private sub command9_click()
text1 = val(text1) * val(text1) * val(text1)
xs = 1
end sub
4樓:匿名使用者
dim a as double
dim b as string
private sub command1_click(index as integer)
text1.text = text1.text & command1(index).caption
end sub
private sub command2_click()
if instr(text1.text, ".") = 0 then
text1.text = text1.text & command2.caption
end if
if left(text1.text, 1) = "." then
text1.text = "0" & text1.text
end if
end sub
private sub command3_click()
if text1.text = "" then
text1.text = a
exit sub
end if
select case b
case "+"
a = a + val(text1.text)
case "-"
a = a - val(text1.text)
case "x"
a = a * val(text1.text)
case "÷"
if text1.text = "0" then
text1.text = "0"
else
a = a / val(text1.text)
end if
end select
text1.text = a
end sub
private sub command4_click(index as integer)
if text1.text = "" then
b = command4(index).caption
exit sub
end if
if b = "" then
a = text1.text
b = command4(index).caption
text1.text = ""
exit sub
end if
select case b
case "+"
a = a + val(text1.text)
case "-"
a = a - val(text1.text)
case "x"
a = a * val(text1.text)
case "÷"
if text1.text = "0" then
text1.text = "0"
else
a = a / val(text1.text)
end if
end select
text1.text = ""
b = command4(index).caption
text2.text = a
end sub
private sub form_load()
b = ""
end sub
private sub text1_keypress(keyascii as integer)
if instr("1234567890.", chr(keyascii)) = 0 then keyascii = 0
if chr(keyascii) = "." and instr(text1.text, ".") <> 0 then keyascii = 0
end sub
表示式計算器的設計與實現VB
option explicit public function str18 num as string as double dim i l lstart dim stemp dtemp dtemp2 if num vbnullstring then exit function lstart inst...
VB中設計加法計算器,怎麼按按鈕能將數字連起來。如 按兩
private sub command9 click text1 text1.text command9.caption end sub 用字串連線就行了 angel的 你的按鈕上比如是9 那你就 9 是8 就 8 text1.text text1.text 9text1.text text1.te...
程式設計設計簡單的計算器程式,程式設計設計一個簡單的計算器程式
這種運算比較麻煩,不過4種運算子號優先順序相同應該簡單寫,我這裡有個演算法,能進行簡單的四則運算,delphi的,供參考 function math evaluate s0 string extended function evaluate s0 string extended forward pr...