用VB製作任意多個多位數的四則運算,求高手

2022-03-13 02:19:30 字數 5830 閱讀 8320

1樓:吾桐語

3個text ,1個list(屬性list:+ - * / ),1個command( 屬性caption:= )

private sub command1_click()

select case list1.text

case "+"

text3.text = val(text1.text) + val(text2.text)

case "-"

text3.text = val(text1.text) - val(text2.text)

case "*"

text3.text = val(text1.text) * val(text2.text)

case "/"

if val(text2.text) <> 0 then

text3.text = val(text1.text) / val(text2.text)

else

msgbox "被0除"

text2.text = ""

text2.setfocus

end if

end select

end sub

2樓:匿名使用者

dim x as single, y as single, fh as string

private sub command1_click(index as integer)

dim k as integer

k = command1(index).index

if k <> 10 then

if right(text1.text, 1) = "." then

text1.text = text1.text & k

elseif int(val(text1.text)) = val(text1.text) and right(text1.text, 1) <> "." then

text1.text = val(text1.text) * 10 + k

elseif int(val(text1.text)) <> val(text1.text) and right(text1.text, 1) <> "." then

text1.text = text1.text & k

end if

else

text1.text = text1.text & "."

end if

if fh = "" then

x = val(text1.text)

else

y = val(text1.text)

end if

end sub

private sub command2_click(index as integer)

dim k1 as integer

k1 = command2(index).index

text1.text = ""

if command2(k1).caption = "+" then

fh = "+"

elseif command2(k1).caption = "-" then

fh = "-"

elseif command2(k1).caption = "*" then

fh = "*"

elseif command2(k1).caption = "/" then

fh = "/"

end if

end sub

private sub command3_click()

if x <> 0 and y <> 0 then

if fh = "+" then

text1.text = x + y

elseif fh = "-" then

text1.text = x - y

elseif fh = "*" then

text1.text = x * y

elseif fh = "/" then

if y = 0 then

msgbox "除數不能為0", 16, "錯誤!"

exit sub

end if

text1.text = x / y

end if

x = val(text1.text)

else

msgbox "運算元不足!", 16, "錯誤!"

end if

end sub

private sub command4_click()

text1.text = "": x = 0: y = 0: fh = ""

end sub

private sub form_load()

text1.text = "": x = 0: y = 0: fh = ""

end sub

3樓:

加減乘除不都一樣使用嗎?

加 +減 -

乘 *除 /

4樓:

5樓:貴州遵義發郎中

原始碼挺多的,給你乙個自己下了參考

6樓:橫掃千軍

我也剛學,聽說很容易。

如何用vb做兩位數四則運算器?

7樓:郯沛柔盈詠

很簡單的:視窗放入四個command控制項(caption屬性分別為+、-、x、÷),三個text控制項,再放入三個label控制項(caption屬性分別為:運算元1、運算元2和計算結果),視窗的caption屬性改為「四則運算」

**如下:

private

subcommand1_click()

ifval(text1.text)

+val(text2.text)

<>int(val(text1.text)

+val(text2.text))

then

text3.text

=format(val(text1.text)+val(text2.text),

"0.######")

else

text3.text

=val(text1.text)

+val(text2.text)

endif

endsub

private

subcommand2_click()

ifval(text1.text)

-val(text2.text)

<>int(val(text1.text)

-val(text2.text))

then

text3.text

=format(val(text1.text)-val(text2.text),

"0.######")

else

text3.text

=val(text1.text)

-val(text2.text)

endif

endsub

private

subcommand3_click()

ifval(text1.text)

*val(text2.text)

<>int(val(text1.text)

*val(text2.text))

then

text3.text

=format(val(text1.text)*val(text2.text),

"0.######")

else

text3.text

=val(text1.text)

*val(text2.text)

endif

endsub

private

subcommand4_click()

ifval(text1.text)

/val(text2.text)

<>int(val(text1.text)

/val(text2.text))

then

text3.text

=format(val(text1.text)/val(text2.text),

"0.######")

else

text3.text

=val(text1.text)

/val(text2.text)

endif

endsub

8樓:匿名使用者

option explicit

dim x as integer, y as integer, js as integer, arr, a as string

public cuo as integer, zq as integer, sum as integer, k as string

private sub command1_click()

endend sub

private sub command2_click()

randomize

x = int((9 * rnd) + 1)

y = int((9 * rnd) + 1)

k = arr(int(rnd * 4))

select case k

case "+"

js = x + y

case "-"

if y > x then a = x: x = y: y = a

js = x - y

case "×"

js = x * y

case else

if y > x then a = x: x = y: y = a

js = x / y

end select

label1.caption = trim(str(x)) & k & trim(str(y)) & "="

text1.text = ""

text1.setfocus

end sub

private sub form_load()

arr = array("+", "-", "×", "÷")

text2.enabled = false

text3.enabled = false

text4.enabled = false

text5.enabled = false

end sub

private sub text1_keypress(keyascii as integer)

if keyascii = 13 then

if label1.caption <> "" then

sum = sum + 1

if val(text1.text) = js then

zq = zq + 1

picture1.print label1.caption & val(text1.text) & " " & "√"

else

picture1.print label1.caption & val(text1.text) & " " & "×"

cuo = cuo + 1

end if

text2.text = sum

text3.text = zq

text4.text = cuo

text5.text = format(str(zq / sum) * 100, "0.00") & "%"

command2_click

end if

keyascii = 0

end if

end sub

怎麼用VB製作倒計時,怎麼用VB製作一個倒計時?

窗體中放置三個command 三個label 一個timer控制元件,在form load過程中已經說明了控制元件用途,其中label1是顯示分鐘數,label2是顯示秒數,如下 dim js as integer 這裡宣告瞭一個全域性變數,儲存計時數 private sub command1 cl...

vb編寫記事本問題,用VB製作乙個簡單記事本問題!

richtextbox的大部分功能textbox都能實現,只是比較麻煩點而已。開啟和寫入檔案用open語句 open xx.txt for input as 1 讀取和寫入用line input和print。例 private sub command1 click 讀取檔案 open xx.txt ...

怎樣用ps做任意形狀的雲彩,ps如何製作雲彩效果

方法是 1 新建文件,填充白色。2 設定前景色和背景色,分別為藍色和白色 如果需要特別顏色的雲彩,可以把前景色和前景色設定所需要的顏色 3 濾鏡 渲染 雲彩 ps如何製作雲彩效果 怎麼用ps做出自己想要的形狀的雲 製作步du驟 1.首先我們新建乙個zhi 400 400的文件,設定 dao前景色81...