Public C護(hù)激篙刻蕻灸戈熏恭抹lass Form1
成都創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計(jì)、做網(wǎng)站與策劃設(shè)計(jì),乾安網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:乾安等地區(qū)。乾安做網(wǎng)站價(jià)格咨詢:028-86922220
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c As Char
c = Trim(TextBox3.Text)
Select Case c
Case "+"
TextBox4.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
Case "-"
TextBox4.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
Case "*"
TextBox4.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
Case "\"
If Val(TextBox2.Text) = 0 Then
MsgBox("分母為0")
Else
TextBox4.Text = Val(TextBox1.Text) \ Val(TextBox2.Text)
End If
Case "/"
If Val(TextBox2.Text) = 0 Then
MsgBox("分母為0")
Else
TextBox4.Text = Val(TextBox1.Text) / Val(TextBox2.Text)
End If
End Select
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
你自己加窗體和空件吧
Private Sub a1_Click()
X = Val(Text1.Text)
Y = Val(Text2.Text)
s = X + Y
Text3.Text = s
Text3.Locked = True
End Sub
Private Sub a2_Click()
X = Val(Text1.Text)
Y = Val(Text2.Text)
s = X - Y
Text3.Text = s
Text3.Locked = True
End Sub
Private Sub a3_Click()
X = Val(Text1.Text)
Y = Val(Text2.Text)
s = X * Y
Text3.Text = s
Text3.Locked = True
End Sub
Private Sub a4_Click()
X = Val(Text1.Text)
Y = Val(Text2.Text)
s = X / Y
Text3.Text = s
Text3.Locked = True
End Sub
不會(huì)的叫我 在線談
以下是一個(gè)簡單的+-*/的計(jì)算器代碼,按鈕采用數(shù)組,text2不可見。詳情也可在我的百度空間里查看“vb6 比較簡單的計(jì)算器代碼”下載源文件和說明。
Function Eval(ByVal Expressions As String) As String '文本運(yùn)算vbs
Dim Mssc As Object
Set Mssc = CreateObject("MSScriptControl.ScriptControl")
Mssc.Language = "vbscript"
On Error GoTo EvalErr
Eval = Mssc.Eval(Expressions)
Exit Function
EvalErr:
Exit Function
End Function
Private Sub Command1_Click(Index As Integer)
Dim i As Long, j As Long
For i = 0 To 10 '數(shù)字輸出0-9和小數(shù)點(diǎn),輸入按鈕的Caption值
If Index = i Then
Text2 = Text2 Command1(i).Caption
Text1 = Format$(Eval(Text2), "0.########") '格式化小于1大于-1的數(shù),下同
End If
Next i
For j = 11 To 14 '運(yùn)算符號(hào)輸出+-*/,輸入按鈕的Caption值
If Index = j Then
Text1 = Format$(Eval(Text2), "0.########")
Text2 = Text1 Command1(j).Caption
End If
Next j
End Sub
我給你做個(gè)簡單的 吧 只做 + - * \ 創(chuàng)建工程后 2個(gè)textbox 文本框控件 4個(gè)command 按紐控件 1個(gè)lalbel 標(biāo)簽控件 代碼實(shí)現(xiàn)如下:
dim a as integer , b as integer, sum as integer
a=text1.text
b=text2.text
Private Sub command1_Click()
sum=a+b
lalbel1.caption=sum
end sub
Private Sub command2_Click()
sum=a-b
lalbel1.caption=sum
end sub
Private Sub command3_Click()
sum=a*b
lalbel1.caption=sum
end sub
Private Sub command4_Click()
sum=a\b
lalbel1.caption=sum
end sub
代碼就這樣 , 按照你的要求寫的 希望給我加分哦