1樓:
dim num1, num2 as single '(下面是用來處理數字的)
dim strnum1, strnum2 as string
dim firstnum as boolean '判斷是否是數字開頭
dim pointflag as boolean '判斷是否已有小數點'(這是處理小數點的)
dim runsign as integer '儲存運算子號(下面是處理四則運算的)
dim signflag as boolean '判斷是否已有運算子號
sub run() ' 建立過程
num1 = val(strnum2)
num2 = val(strnum1)
select case runsign
case 1 '加
equal = num1 + num2
case 2 '減
equal = num1 - num2
case 3 '乘
equal = num1 * num2
case 4 '除
equal = num1 / num2
end select
strnum2 = str(equal)
strnum1 = strnum2 '(如再按同一個運算子時,在原有的數上和結果再運算一次)
text1.text = strnum2
end sub
sub cleardata()
num1 = 0
num2 = 0
strnum1 = ""
strnum2 = ""
firstnum = true
pointflag = false
runsign = 0
signflag = false
text1.text = "0."
end sub
private sub command1_click(index as integer)
select case index
case 0 to 9
if firstnum then
strnum1 = str(index) '實型轉字元型
firstnum = false '初賦值為假
else '非初賦值
strnum1 = strnum1 + str(index) '("+"是連線符)
end if
text1.text = strnum1 '顯示
case 10
if not pointflag then '如果沒有小數點(not是非)
if firstnum then '如果是第一個字元
strnum1 = "0."
firstnum = false
else
strnum1 = strnum1 + "."
end if
else '已有小數點
exit sub '則退出單擊事件
end if
pointflag = true
text1.text = strnum1
case 12 to 15
firstnum = true '使下一次可以輸入新資料
pointflag = false '還原標記值
if signflag then '前面已有運算子未運算(signflag的值是ture)
call run '(呼叫前面建立的過程)
else
signflag = true
strnum2 = strnum1 '把字串1複製給字串2
strnum1 = "" '字串1清空
end if
runsign = index - 11 '儲存鍵入的運算子
case 11 '(等於號的處理)
if not signflag then
text1.text = strnum1
equal = val(strnum1)
firstnum = true
pointflag = false
else
call run
signflag = false
end if
case else '清除按鈕
call cleardata
end select
end sub
private sub form_load()
num1 = 0
num2 = 0
strnum1 = ""
strnum2 = ""
firstnum = true
pointflag = false
runsign = 0
signflag = false
end sub
2樓:an狩獵神
因為你的a,b.c變數定義錯了,你應定為整型變數private sub command1_click()dim a as integer
dim b as integer
dim c as integer
a =val( text1.text)
b = val(text2.text)
c = a + b
msgbox "結果是" & c
end sub
這樣就對了,記住"+"在vb裡,對字元型變數而言,其是連線符.
如何用vb進行加減乘除運算?
3樓:
可以直接使用阿拉拍數字或變數加上運算子號組成運算就可以了。
運算子號:+(加),-(減),*(乘),/(除)。
例如:dim sum
sum=4+6
sum=3*5+2-1
4樓:匿名使用者
private sub command1_click()
text3.text = val(text1.text) + val(text2.text)
end sub
private sub command2_click()
text3.text = val(text1.text) - val(text2.text)
end sub
private sub command3_click()
text3.text = val(text1.text) * val(text2.text)
end sub
private sub command4_click()
text3.text = val(text1.text) / val(text2.text)
end sub
四個按bai鈕du分別實zhi現加dao
減乘除回功答能
5樓:匿名使用者
你的運算子號在**放著都不告訴一下啊
vb編寫簡單四則運算
6樓:匿名使用者
因為你的a,b.c變數定義錯了,你應定為整型變數private sub command1_click()dim a as integer
dim b as integer
dim c as integer
a =val( text1.text)
b = val(text2.text)
c = a + b
msgbox "結果是" & c
end sub
這樣就對了,記住"+"在vb裡
專,對字元型變數屬而言,其是連線符.
7樓:匿名使用者
vb寫的四抄
則運襲算如下:
private sub command1_click()on error goto err
dim s as object
dim bds as string '表示式set s = createobject("msscriptcontrol.scriptcontrol")
s.language = "vbscript"
bds = text1
text2 = s.eval(bds)
exit sub
err:
text2 = err.descriptionend sub
8樓:匿名使用者
樓上的說對了,不再重複!
怎樣用vb製作一個四則運算的程式
9樓:匿名使用者
i=a*b/c+d-e
怎麼用vb編寫四則運算計算器
10樓:
我的計算器
option explicit
dim focustext as vb.textbox
dim pd as boolean
dim x as double
dim y as double
dim ch as integer
private sub command1_click(index as integer)
on error resume next
focustext.setfocus
if index sendkeys index
elseif index = 10 then
ch = index - 10
x = val(text1.text)
text1.text = ""
elseif index = 14 then
y = val(text1.text)
select case ch
case 0
text1.text = x + y
case 1
text1.text = x - y
case 2
text1.text = x * y
case 3
text1.text = x / y
end select
elseif index = 15 then
focustext.setfocus
sendkeys ""
elseif index = 16 then
focustext.setfocus
sendkeys "."
end if
end sub
'防止輸入多個小數點以及出數字外的其他字元
private sub text1_keypress(keyascii as integer)
if (keyascii 57) and keyascii 46 and keyascii 8 then
keyascii = 0
end if
if pd = true and keyascii = 46 then
keyascii = 0
end if
if pd = false and keyascii = 46 then
pd = true
keyascii = 46
end if
end sub
'防止 ctrl + v 貼上
private sub text1_keydown(keycode as integer, shift as integer)
if keycode = vbkeyv and shift = vbctrlmask then
text1.enabled = false
clipboard.clear
text1.enabled = true
end if
end sub
'防止右鍵貼上
private sub text1_mousedown(button as integer, shift as integer, x as single, y as single)
if button = vbrightbutton then
text1.enabled = false
clipboard.clear
text1.enabled = true
end if
end sub
private sub text1_lostfocus()
set focustext = text1
end sub
介面如下
0為command1(0)1為command1(1)依次類推
←為command1(15) 小數點為command1(16)
貼子相關**:
介面可以到
四則運算題目,四則運算題目
1.3 7 49 9 4 3 2.8 9 15 36 1 27 3.12 5 6 2 9 3 4.8 5 4 1 4 5.6 3 8 3 8 6 6.4 7 5 9 3 7 5 9 7.5 2 3 2 4 5 8.7 8 1 8 1 9 9.9 5 6 5 6 10.3 4 8 9 1 3 11.7...
四則運算意義的法則,四則運算的意義與法則
在數學中,當一級運算 加減 和二級運算 乘除 同時出現在乙個式子中時,它們的運算順序是先乘除,後加減,如果有括號就先算括號內後算括號外,同一級運算順序是從左到右,這樣的運算叫四則運算。四則是指加法 減法 乘法 除法的計算法則。一道四則運算的算式並不需要一定有四種運算符號,一般指由兩個或兩個以上運算符...
四則運算的關係是什麼,幾種四則運算之間有什麼關係四則運算各部分之間有什麼關係
仁碧曼典添 1 整數加 減計演算法則 1 要把相同數位對齊,再把相同計數單位上的數相加或相減 7 2 9 2 哪一位滿十就向前一位進。9 6 15 2 小數加 減法的計演算法則 1 計算小數加 減法,先把各數的小數點對齊 也就是把相同數位上的數對齊 5.2 4.7 9.9 2 再按照整數加 減法的法...