判斷吧,如果點擊+按肢鏈鈕,則一個全局變量為1,-按鈕,則全鬧陵局變量為2.以此類推,歷彎孫然后if或case判斷哪個數(shù),如果為1,就兩個數(shù)相加。
成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),師宗企業(yè)網(wǎng)站建設(shè),師宗品牌網(wǎng)站建設(shè),網(wǎng)站定制,師宗網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,師宗網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
我用VB做的你看能不能用
Public b
Public c
Public d
Public e
Public f
Private Sub Command14_Click()
d = ""
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Exit Sub
'c = Text1.Text
If b = "" Then Exit Sub
If e = "+" Then
d = f + b
Else
If e = "-" Then
d = f - b
Else
If e = "*" Then
d = f * b
Else
If e = "/" Then
If b = 0 Then
MsgBox "被除數(shù)不能為零!"
Exit Sub
End If
d = f / b
Else
MsgBox "錯誤操作!"
End If
End If
End If
End If
Text1.Text = d
b = ""
c = ""
e = ""
End Sub
Private Sub Command15_Click()
Text1.Text = ""
b = ""
c = ""
d = ""
e = ""
f = ""
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Command1_Click()
'判斷開頭有運算符就清零
If Text1.Text = "握戚+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
'判斷開頭有0就禁止輸入數(shù)字
If Text1.Text = "0" Then
Else
a = 1
'發(fā)現(xiàn)運算結(jié)果就清零
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text '得到當(dāng)前操作數(shù)
End Sub
Private Sub Command2_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 2
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command3_Click()
If Text1.Text = "+" Or Text1.Text = "帆皮局-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 3
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command4_Click()
If Text1.Text = "態(tài)讓+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 4
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command5_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 5
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command6_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 6
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command7_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 7
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command8_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 8
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command9_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 9
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command10_Click()
If b = "" Then Exit Sub
a = "+"
e = "+"
f = b
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command11_Click()
If b = "" Then Exit Sub
f = b
a = "-"
e = "-"
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command12_Click()
If b = "" Then Exit Sub
a = "*"
e = "*"
f = b
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command13_Click()
If b = "" Then Exit Sub
a = "/"
e = "/"
f = b '把操作數(shù)1提取出來
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command16_Click()
'判斷有運算符就清零
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
'判斷有零和空值就禁止輸入0
'發(fā)現(xiàn)運算結(jié)果就清零
If d "" Then Text1.Text = "": d = ""
If Text1.Text = "0" Then
Else
a = 0
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
b = Text1.Text
End If
End Sub
不知道你想要哪種,偶是新手,只會最簡單的
首先拖出三個text,再拖出4個Command按鈕 caption分別為+ - * / 這樣就準(zhǔn)備就緒了
先講一下簡單用法,第一纖森個text是第一個加數(shù)/被減數(shù)虛豎悔/因數(shù)/被除數(shù),而第二個text是第二個加數(shù)/減數(shù)/因數(shù)/除數(shù),第三個text是和/差/積/商,在text1輸入一個數(shù),text2輸入一個,然后分別點擊command“+ - * /”text3就差正會出現(xiàn)結(jié)果
然后隨便單擊一個窗口,把里面的文字刪去,再寫上:
Private Sub Command1_Click()
Text3.Text = Str$(Val(Text1.Text) + Val(Text2.Text))
End Sub
Private Sub Command2_Click()
Text3.Text = Str$(Val(Text1.Text) - Val(Text2.Text))
End Sub
Private Sub Command3_Click()
Text3.Text = Str$(Val(Text1.Text) * Val(Text2.Text))
End Sub
Private Sub Command4_Click()
Text3.Text = Str$(Val(Text1.Text) / Val(Text2.Text))
End Sub
然后運行,應(yīng)該就可以了
在窗體上添加一個Text1控件, 用于輸入電費單價;再添加一個Text2控件,用于輸入渣局鬧電量;再添加一個Text3, 用于輸出計算結(jié)果;最后添加一個Command1按鈕如罩。代碼臘敗如下:
Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
End Sub
標(biāo)題名稱:vb點虐
怎么做計算器 vbs做計算器
當(dāng)前網(wǎng)址:http://jinyejixie.com/article40/ddpeeho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、自適應(yīng)網(wǎng)站、Google、品牌網(wǎng)站建設(shè)、面包屑導(dǎo)航、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)