帮忙用VB制作一个计算器

2025-01-19 11:59:01
推荐回答(6个)
回答1:

你不都没200分。你只有5分了。给你做一个简单得吧
控件有1个按钮 2个label 2个text 4个option数组控件 代码如下

Private Sub Command1_Click()
Label2.Caption = "等于:"
If Option1(0).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) + Val(Text2.Text))
If Option1(1).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) - Val(Text2.Text))
If Option1(2).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) * Val(Text2.Text))
If Option1(3).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) / Val(Text2.Text))
End Sub

Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0
Label1.Caption = "+"
Case 1
Label1.Caption = "-"
Case 2
Label1.Caption = "*"
Case 3
Label1.Caption = "/"
End Select
End Sub

回答2:

给你个十进制的参考
Option Explicit
Dim a As Double, b As Double
Dim c As String
Dim clear As Boolean

Private Sub Command17_Click() 'C清空
Text1.Text = ""
End Sub

Private Sub Digits_click(index As Integer) '0-9十个command的名称均为 Digits
If clear Then
Text1.Text = ""
clear = False
End If
Text1.Text = Text1.Text + Digits(index).Caption
End Sub

Private Sub Command10_Click() '+(加)
a = Val(Text1.Text)
c = "+"
Text1.Text = ""
End Sub

Private Sub Command11_Click() '-(减)
a = Val(Text1.Text)
c = "-"
Text1.Text = ""
End Sub

Private Sub Command12_Click() '*(乘)
a = Val(Text1.Text)
c = "*"
Text1.Text = ""
End Sub

Private Sub Command13_Click() '/ (除)
a = Val(Text1.Text)
c = "/"
Text1.Text = ""

End Sub

Private Sub Command15_Click() '.(小数点)
If InStr(Text1.Text, ".") Then
Exit Sub
Else
Text1.Text = Text1.Text + "."
End If

End Sub

Private Sub Command16_Click() '=(等于)
Dim r As Double
b = Val(Text1.Text)
If c = "+" Then r = a + b
If c = "-" Then r = a - b
If c = "*" Then r = a * b
If c = "/" And b <> "0" Then r = a / b
Text1.Text = r
clear = True
End Sub

回答3:

Private Sub Command1_Click()

If Option1.Value = True Then

Text5.Text = Val(Text1) + Val(Text2)

Text3.Text = Oct(Text5)

Text4.Text = Hex(Text5)

ElseIf Option2.Value = True Then

Text5.Text = Val(Text1) - Val(Text2)

Text3.Text = Oct(Text5)

Text4.Text = Hex(Text5)

ElseIf Option3.Value = True Then

Text5.Text = Val(Text1) * Val(Text2)

Text3.Text = Oct(Text5)

Text4.Text = Hex(Text5)

ElseIf Option4.Value = True Then

Text5.Text = Val(Text1) / Val(Text2)

Text3.Text = Oct(Text5)

Text4.Text = Hex(Text5)

End If

End Sub

Private Sub Form_Load()

Option1.Value = True

Option1.Caption = "+": Option2.Caption = "-": Option3.Caption = "*": Option4.Caption = "/"

Command1.Caption = "=": Label1.Caption = "八进制": Label2.Caption = "十六进制": Label3.Caption = "十进制"

End Sub

一段简单的代码

回答4:

z这个要实现起来很简单
VAL(TEXT1) * VAL(TEXT2)
* 换成你要的-+*/

要换成8进制16进制 那些要自己写模块才完美. 单单的几段代码不可能完成

回答5:

哈哈 试有期一级 200分 骗人去吧 呵呵!!!VB写计算器 最简单的 初学者一般都练习过的

回答6:

占位置