vb 编写简易计算器
文本框从左起text1text2text30-9command1运算符command2=command5正负号command3小数点是command4最好能自动判断小数点...
文本框从左起text1 text2 text3
0-9 command1
运算符 command2
= command5
正负号 command3
小数点是 command4
最好能自动判断小数点
还有就是在text1 输入数字后,按运算符,光标移动到text2,怎么在text2输入数字呢
初学者,希望简单点好。谢谢
Private Sub Command1_Click(Index As Integer)
Text1.SetFocus
sum1 = Text1.Text + Command1(Index).Caption
Text1.Text = sum1
Text1.LostFocus
sum2 = Text2.Text + Command1(Index).Caption
Text2.Text = sum2
End Sub
我自己想法是这样的,如果光标在text1,则按command1 在text1输入,按运算符号,则光标移动到text2,并输入数据,怎么实现。 展开
0-9 command1
运算符 command2
= command5
正负号 command3
小数点是 command4
最好能自动判断小数点
还有就是在text1 输入数字后,按运算符,光标移动到text2,怎么在text2输入数字呢
初学者,希望简单点好。谢谢
Private Sub Command1_Click(Index As Integer)
Text1.SetFocus
sum1 = Text1.Text + Command1(Index).Caption
Text1.Text = sum1
Text1.LostFocus
sum2 = Text2.Text + Command1(Index).Caption
Text2.Text = sum2
End Sub
我自己想法是这样的,如果光标在text1,则按command1 在text1输入,按运算符号,则光标移动到text2,并输入数据,怎么实现。 展开
1个回答
展开全部
Dim focus%, op%, bfin
Private Sub Command1_Click(Index As Integer)
If bfin Then Call Form_Load
If focus = 1 Then
Text1 = Text1 & Index
Else
Text2 = Text2 & Index
End If
End Sub
Private Sub Command2_Click(Index As Integer)
If focus <> 1 Then Exit Sub
Text2.SetFocus
focus = 2
op = Index + 1
Label1 = Choose(op, "+", "-", "*", "/")
End Sub
Private Sub Command3_Click()
If focus = 1 Then
Text1 = -1 * Text1
Else
Text2 = -1 * Text2
End If
End Sub
Private Sub Command4_Click()
If focus = 1 Then
Text1 = Text1 & "."
Else
Text2 = Text2 & "."
End If
End Sub
Private Sub Command5_Click()
Select Case op
Case 1
Text3 = Val(Text1) + Val(Text2)
Case 2
Text3 = Val(Text1) - Val(Text2)
Case 3
Text3 = Val(Text1) * Val(Text2)
Case 4
Text3 = Val(Text1) / Val(Text2)
End Select
bfin = True
End Sub
Private Sub Command6_Click()
If focus = 1 Then
Text1 = Left(Text1, Len(Text1) - 1)
Else
Text2 = Left(Text2, Len(Text2) - 1)
End If
End Sub
Private Sub Command7_Click()
Call Form_Load
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
Text3 = ""
focus = 1
Label1 = ""
bfin = False
'Text1.SetFocus
End Sub
Private Sub Command1_Click(Index As Integer)
If bfin Then Call Form_Load
If focus = 1 Then
Text1 = Text1 & Index
Else
Text2 = Text2 & Index
End If
End Sub
Private Sub Command2_Click(Index As Integer)
If focus <> 1 Then Exit Sub
Text2.SetFocus
focus = 2
op = Index + 1
Label1 = Choose(op, "+", "-", "*", "/")
End Sub
Private Sub Command3_Click()
If focus = 1 Then
Text1 = -1 * Text1
Else
Text2 = -1 * Text2
End If
End Sub
Private Sub Command4_Click()
If focus = 1 Then
Text1 = Text1 & "."
Else
Text2 = Text2 & "."
End If
End Sub
Private Sub Command5_Click()
Select Case op
Case 1
Text3 = Val(Text1) + Val(Text2)
Case 2
Text3 = Val(Text1) - Val(Text2)
Case 3
Text3 = Val(Text1) * Val(Text2)
Case 4
Text3 = Val(Text1) / Val(Text2)
End Select
bfin = True
End Sub
Private Sub Command6_Click()
If focus = 1 Then
Text1 = Left(Text1, Len(Text1) - 1)
Else
Text2 = Left(Text2, Len(Text2) - 1)
End If
End Sub
Private Sub Command7_Click()
Call Form_Load
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
Text3 = ""
focus = 1
Label1 = ""
bfin = False
'Text1.SetFocus
End Sub
追问
光标在text1时,按command1在text1输入数据,按下运算符command2则光标移动到text2,command1在text2输入数据,怎么实现,谢谢
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询