问一个关于VB的简单的代码
发布网友
发布时间:2022-04-20 08:49
我来回答
共5个回答
热心网友
时间:2023-07-10 03:59
我们现在首先要做的就是拉出Label,准备三个Label,把label1,label2,label3,这些改成第一个数、第二个数、结果。
我们现在要text也要拉出三个,把了text里面text1、text2、text3全部删掉。
我们现在要把command拉出四个,把里面command1-4都给成+-*/
现在我们现在要双击+,我们开始进行输入代码
在里面我们现在要:text3.text=val(text1.text)+val(text2.text)
我们要把这个(text3.text=val(text1.text)+val(text2.text))复制,把里面+号分别改成-*/
如图,就像这样就可以了,可以行径了,如果你在哪个代码里弄错了,你看一下还要哪些没有拉出来,或者你哪个代码输错了。
感谢观看。
热心网友
时间:2023-07-10 03:59
'界面设置如图' 代码如下'已增加操作数正确性验证及 除数不能为0验证Private Sub Command1_Click() If IsNumeric(Text1.Text) And Text1.Text "" And IsNumeric(Text2.Text) And Text2.Text "" Then Select Case Combo1.ListIndex Case 0 Text3.Text = Val(Text1.Text) + Val(Text2.Text) Case 1 Text3.Text = Val(Text1.Text) - Val(Text2.Text) Case 2 Text3.Text = Val(Text1.Text) * Val(Text2.Text) Case 3 If Val(Text1.Text) 0 Then Text3.Text = Val(Text1.Text) / Val(Text2.Text) Else MsgBox "除数不能为0", , "错误" End If End Select Else MsgBox "请输入操作数", , "错误" End IfEnd SubPrivate Sub Form_Load() Combo1.AddItem "+" Combo1.AddItem "-" Combo1.AddItem "*" Combo1.AddItem "/" Combo1.ListIndex = 0 Text1.Text = "" Text2.Text = "" Text3.Text = "" Command1.Caption = "计算" End Sub
热心网友
时间:2023-07-10 04:00
Dim YSF% '定义运算符
Dim S1#, S2# '定义运算中的两个数值
Dim ZT% '定义状态
Dim FH As Boolean '定义符号
Dim XSD As Boolean '定义运算符
Dim CD1%, CD2% '定义与符号有关的两个字符串长度
Dim M1#, M2#, M3#, M4#, M5# '定义用于记忆功能的5个变量
'给运算符赋值,以便在计算结果。
If ZT = 1 Then
Select Case Index
Case 0
YSF = 1
Case 1
YSF = 2
Case 2
YSF = 3
Case 3
YSF = 4
End Select
If M = 1 Then
Label1 = M1
ElseIf M = 2 Then
Label1 = M2
ElseIf M = 3 Then
Label1 = M3
ElseIf M = 4 Then
Label1 = M4
End If
S1 = Val(Label1)
Label1 = ""
ZT = 2
'给XSD和FH从新赋值,以便下一个数能添加小数点
XSD = False
FH = False
End If
'给运算符赋值,以便在计算结果。
If ZT = 1 Then
Select Case Index
Case 0
YSF = 1
Case 1
YSF = 2
Case 2
YSF = 3
Case 3
YSF = 4
End Select
If M = 1 Then
Label1 = M1
ElseIf M = 2 Then
Label1 = M2
ElseIf M = 3 Then
Label1 = M3
ElseIf M = 4 Then
Label1 = M4
End If
S1 = Val(Label1)
Label1 = ""
ZT = 2
'给XSD和FH从新赋值,以便下一个数能添加小数点
XSD = False
FH = False
End If
'给运算符赋值,以便在计算结果。
If ZT = 1 Then
Select Case Index
Case 0
YSF = 1
Case 1
YSF = 2
Case 2
YSF = 3
Case 3
YSF = 4
End Select
If M = 1 Then
Label1 = M1
ElseIf M = 2 Then
Label1 = M2
ElseIf M = 3 Then
Label1 = M3
ElseIf M = 4 Then
Label1 = M4
End If
S1 = Val(Label1)
Label1 = ""
ZT = 2
'给XSD和FH从新赋值,以便下一个数能添加小数点
XSD = False
FH = False
End If
'给运算符赋值,以便在计算结果。
If ZT = 1 Then
Select Case Index
Case 0
YSF = 1
Case 1
YSF = 2
Case 2
YSF = 3
Case 3
YSF = 4
End Select
If M = 1 Then
Label1 = M1
ElseIf M = 2 Then
Label1 = M2
ElseIf M = 3 Then
Label1 = M3
ElseIf M = 4 Then
Label1 = M4
End If
S1 = Val(Label1)
Label1 = ""
ZT = 2
'给XSD和FH从新赋值,以便下一个数能添加小数点
XSD = False
FH = False
End If
顺序是+-*/
热心网友
时间:2023-07-10 04:00
Dim op1 As Byte
Dim ops1&, ops2&
Dim res As Boolean
Private Sub Command1_Click(i As Integer)
If Not res Then
Label1.Caption = Label1.Caption & i
Else
Label1.Caption = i
res = False
End If
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
End Sub
Private Sub Command3_Click()
ops2 = Label1.Caption
Select Case op1
Case 0
Label1.Caption = ops1 + ops2
Case 1
Label1.Caption = ops1 - ops2
Case 2
Label1.Caption = ops1 * ops2
Case 3
Label1.Caption = ops1 / ops2
End Select
res = True
End Sub
Private Sub Command4_Click(j As Integer)
ops1 = Label1.Caption
op1 = j
Label1.Caption = ""
End Sub
Private Sub Command5_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
res = False
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Now
End Sub
热心网友
时间:2023-07-10 04:01
控件:
四个textbox
一个command键
private sub command1_click()
select case cstr(text2.text)
case "+"
text4.text=val(text1.text)+val(text3.text)
case "-"
text4.text=val(text1.text)-val(text3.text)
case "*"
text4.text=val(text1.text)*val(text3.text)
case "/"
if val(text3.text)=0 then
msgbox "分母不能为零"
text3.setfoucs
text3.text=""
endif
text4.text=val(text1.text)/val(text3.text)
end select
end sub
这够简单了吧!!!???