3个回答
展开全部
http://post.baidu.com/f?kz=209715785
我的计算器枝昌凯
Option Explicit
Dim FocusText As VB.TextBox
Dim pd As Boolean
Dim x As Double
Dim y As Double
Dim ch As Integer
Private Sub Command1_Click(Index As Integer)
On Error Resume Next
FocusText.SetFocus
If Index SendKeys Index
ElseIf Index = 10 Then
ch = Index - 10
x = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 14 Then
y = Val(Text1.Text)
Select Case ch
Case 0
Text1.Text = x + y
Case 1
Text1.Text = x - y
Case 2
Text1.Text = x * y
Case 3
Text1.Text = x / y
End Select
ElseIf Index = 15 Then
FocusText.SetFocus
SendKeys "{BS}"
ElseIf Index = 16 Then
FocusText.SetFocus
SendKeys "."
End If
End Sub
'防止输入多个猛唤小数点以及出数字外的其他字符
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii 57) And KeyAscii 46 And KeyAscii 8 Then
KeyAscii = 0
End If
If pd = True And KeyAscii = 46 Then
KeyAscii = 0
End If
If pd = False And KeyAscii = 46 Then
pd = True
KeyAscii = 46
End If
End Sub
'防止 Ctrl + v 粘贴
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyV And Shift = vbCtrlMask Then
Text1.Enabled = False
Clipboard.Clear
Text1.Enabled = True
End If
End Sub
'防止右键粘贴
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Text1.Enabled = False
Clipboard.Clear
Text1.Enabled = True
End If
End Sub
Private Sub Text1_LostFocus()
Set FocusText = Text1
End Sub
界面如下
0为Command1(0)1为迅蔽Command1(1)依次类推
←为Command1(15) 小数点为Command1(16)
贴子相关图片:
界面可以到
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
展开全部
试试这个~
Private Sub Command1_Click()
Label1 = Val(Text1) + Val(Text2)
End Sub
Private Sub Command2_Click()
Label1 = Val(Text1) - Val(Text2)
End Sub
Private Sub Command3_Click()
Label1 = Val(Text1) * Val(Text2)
End Sub
Private Sub Command4_Click()
If Val(Text2) <> 0 Then
Label1 = Val(Text1) / Val(Text2)
Else
MsgBox "除数不兄皮能中尘团卖橘为0"
Text2 = ""
Text2.SetFocus
End If
End Sub
Private Sub Command1_Click()
Label1 = Val(Text1) + Val(Text2)
End Sub
Private Sub Command2_Click()
Label1 = Val(Text1) - Val(Text2)
End Sub
Private Sub Command3_Click()
Label1 = Val(Text1) * Val(Text2)
End Sub
Private Sub Command4_Click()
If Val(Text2) <> 0 Then
Label1 = Val(Text1) / Val(Text2)
Else
MsgBox "除数不兄皮能中尘团卖橘为0"
Text2 = ""
Text2.SetFocus
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单的:窗口放入四个COMMAND控件(Caption属性分别为+、-、X、÷),三个TEXT控件,再放入三个Label控件哪岩(Caption属性分别为:操作数1、操作数渗缓旁2和计算结果),窗口的Caption属性改为“四则运算”丛橡
代码如下:
Private
Sub
Command1_Click()
If
Val(Text1.Text)
+
Val(Text2.Text)
<>
Int(Val(Text1.Text)
+
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
+
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
+
Val(Text2.Text)
End
If
End
Sub
Private
Sub
Command2_Click()
If
Val(Text1.Text)
-
Val(Text2.Text)
<>
Int(Val(Text1.Text)
-
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
-
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
-
Val(Text2.Text)
End
If
End
Sub
Private
Sub
Command3_Click()
If
Val(Text1.Text)
*
Val(Text2.Text)
<>
Int(Val(Text1.Text)
*
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
*
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
*
Val(Text2.Text)
End
If
End
Sub
Private
Sub
Command4_Click()
If
Val(Text1.Text)
/
Val(Text2.Text)
<>
Int(Val(Text1.Text)
/
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
/
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
/
Val(Text2.Text)
End
If
End
Sub
代码如下:
Private
Sub
Command1_Click()
If
Val(Text1.Text)
+
Val(Text2.Text)
<>
Int(Val(Text1.Text)
+
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
+
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
+
Val(Text2.Text)
End
If
End
Sub
Private
Sub
Command2_Click()
If
Val(Text1.Text)
-
Val(Text2.Text)
<>
Int(Val(Text1.Text)
-
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
-
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
-
Val(Text2.Text)
End
If
End
Sub
Private
Sub
Command3_Click()
If
Val(Text1.Text)
*
Val(Text2.Text)
<>
Int(Val(Text1.Text)
*
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
*
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
*
Val(Text2.Text)
End
If
End
Sub
Private
Sub
Command4_Click()
If
Val(Text1.Text)
/
Val(Text2.Text)
<>
Int(Val(Text1.Text)
/
Val(Text2.Text))
Then
Text3.Text
=
Format(Val(Text1.Text)
/
Val(Text2.Text),
"0.######")
Else
Text3.Text
=
Val(Text1.Text)
/
Val(Text2.Text)
End
If
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询