VB計算器做法,用VB編寫計算器,控制元件都弄好了,求程式碼!

時間 2021-10-14 23:40:46

1樓:匿名使用者

dim choice as string

dim current as double

dim prev as double

private const pi = 3.14159265

'equal 為=

'sigh 為+/-(正負號切換)

'cls為清零

'bs 為backspace

'plus為+

'minus為-

'asterisk為*

'slash為/

'num()為數字健控制元件陣列

'point為小數點

private sub form_load()

text1.text = ""

prev = current = 0

end sub

private sub num_click(index as integer)

text1.text = val(text1.text & num(index).caption)

current = val(text1.text)

private sub sign_click()

current = -current

text1.text = current

private sub point_click()

if text1.text = "" then

text1.text = "0."

else

text1.text = text1.text & "."

end if

end sub

private sub bs_click()

text1.text = mid$(text1.text, 1, (len(text1.text) - 1))

private sub plus_click()

text1.text = ""

choice = "+"

prev = current

private sub minus_click()

text1.text = ""

choice = "-"

prev = current

private sub asterisk_click()

text1.text = ""

choice = "*"

prev = current

private sub slash_click()

text1.text = ""

choice = "/"

prev = current

private sub equal_click()

if choice = "+" then

current = prev + current

text1.text = current

elseif choice = "-" then

current = prev - current

text1.text = current

elseif choice = "*" then

current = prev * current

text1.text = current

elseif choice = "/" and current <> 0 then

current = prev / current

text1.text = current

else

msgbox "除數不能為零", vbcritical + vbokonly + vbdefaultbutton1, "出錯"

end if

private sub cls_click()

text1.text = ""

prev = current = 0

根據你的需要我做了個最簡單的計算器

我的qq是:659327515,如果有問題,可以聯絡我,我可以詳細地說一下過程和步驟。^_^

2樓:岔路程式緣

q\q:44\86\74\357\聯\系\

vb製作一個科學計算器怎麼做,跪求答案!!!

用vb編寫計算器,控制元件都弄好了,求**!

3樓:yin幕後的妖

給你一個思路吧,畢竟是

學習,直接看**還不如看思路,然後自己出**好。

介面設計方面,圖中的文字框做顯示屏使用,name設為:text1,

按鈕設為一個控制元件陣列cmd(),

0-9用cmd(0)-cmd(9)表示。

小數點用cmd(10)表示,

加減乘除分別用cmd(11)-cmd(14)表示,

等於用cmd(15)表示

其他的自行決定。

定義一個變數txtnumber,用於儲存第一個因數(計算用)

定義一個變數txtfh用於儲存運算子號

下面是部分**,不懂再追問。

private sub cmd(index as integer)_click()

select case index ‘index代表我們按下的按鈕

case 0 to 9

text1=text1 & cmd.caption

case 10 ’小數點的處理,在第一個前加上“0”

if texe1="" then

text1="0."

else

text1= text1 & "."

end if

case 11 to 14

if txtnumber=“”then ‘檢查是否按過符號鍵

txtnumber=text1

text1=""

txtfh=cmd.caption

else ’按過符號鍵就先將前面的數進行計算

txtnumber= js(txtnumber,val(text1),txtfh)

text1=""

txtfh=cmd.caption

end if

case 15 ‘計算結果,並顯示

if txtfh<>" " then

text1=js(txtnumber,val(text1),txtfh)

txtnumber=""

elseif text1="" then

text1=txtnumber

txtnumber=""

end if

case 16

...........................

end select

end sub

下面**用於計算:

private function js(num1 as integer , num2 as integer , fh as string )

select case fh

case "+"

js=num1+num2

case "-"

js=num1-num2

case "x"

js=num1 * num2

case "/"

js=num1/num2

end select

end function

暫時先打這些**,其餘的望樓主舉一反三,不懂再問

求vb簡易計算器的**

編寫控制台計算器,編寫乙個控制台計算器

認同上樓說的 這個東東不易做 這個東東,別說控制台,就是用窗體做,理論上難度是一樣的.本人自問也接觸程式這一塊好多年了,這個真不好做.印象中,看過某版本的 資料結構 中提出,可以用堆疊來做,哦,那本書是c語言的.至少得判斷括號內外,還得依四則運算的優先順序,用堆疊或許是一種很不錯的方法來的.最最最嚴...

用VB做簡單的計算器,該怎麼做,用VB做一個簡單的計算器,該怎麼做?

du瓶邪 option explicit dim op1,op2 前面輸入的運算元 dim decimalflag as integer 小數點仍然存在嗎?dim numops as integer 運算元個數 dim lastinput 指示上一次按鍵事件的型別 dim opflag 指示未完成的...

貸款買車計算器,貸款買車計算器

計算方法 根據一般房貸還款方式的計算公式分為兩種 一 等額本息計算公式 計算原則 銀行從每月月供款中,先收剩餘本金利息,後收本金 利息在月供款中的比例中隨剩餘本金的減少而降低,本金在月供款中的比例因增加而公升高,但月供總額保持不變。需要注意的是 1 各地城市公積金貸款 1 最高額度要結合當地具體來看...