VB中按一次按钮command的caption属性为"1"再按一次为"22",再按一次为”33“ 这样的程序怎么写啊
VB中按一次按钮command的caption属性为"1"再按一次为"22",再按一次为”33“再按一次弹出对话框,有YES和NO两个选项,点YES执行一个程序,点NO运...
VB中按一次按钮command的caption属性为"1"再按一次为"22",再按一次为”33“
再按一次弹出对话框,有YES和NO两个选项,点YES 执行一个程序,点NO 运行另一个 展开
再按一次弹出对话框,有YES和NO两个选项,点YES 执行一个程序,点NO 运行另一个 展开
4个回答
展开全部
可以了
VERSION 5.00
Begin VB.Form frmMain
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 3 'Fixed Dialog
Caption = "简单计算器"
ClientHeight = 2430
ClientLeft = 45
ClientTop = 435
ClientWidth = 3150
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2430
ScaleWidth = 3150
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command10
Caption = "^"
Height = 375
Left = 1920
TabIndex = 22
Top = 1920
Width = 495
End
Begin VB.PictureBox picDisplay
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 120
ScaleHeight = 225
ScaleWidth = 2865
TabIndex = 19
Top = 120
Width = 2895
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BorderStyle = 0 'None
Height = 255
Left = 240
Locked = -1 'True
TabIndex = 20
Top = 0
Width = 2535
End
Begin VB.Label lblOperation
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 60
TabIndex = 21
Top = 0
Width = 255
End
End
Begin VB.CommandButton Command9
Caption = "退格"
Height = 375
Left = 1920
TabIndex = 18
Top = 480
Width = 495
End
Begin VB.CommandButton Command8
Caption = "清零"
Height = 375
Left = 2520
TabIndex = 17
Top = 480
Width = 495
End
Begin VB.CommandButton cmdDot
Caption = "."
Height = 375
Left = 120
TabIndex = 16
Top = 1920
Width = 495
End
Begin VB.CommandButton Command7
Caption = "Sqrt"
Height = 375
Left = 2520
TabIndex = 15
Top = 1920
Width = 495
End
Begin VB.CommandButton Command6
Caption = "="
Height = 375
Left = 1320
TabIndex = 14
Top = 1920
Width = 495
End
Begin VB.CommandButton Command5
Caption = "/"
Height = 375
Left = 2520
TabIndex = 13
Top = 1440
Width = 495
End
Begin VB.CommandButton Command4
Caption = "*"
Height = 375
Left = 1920
TabIndex = 12
Top = 1440
Width = 495
End
Begin VB.CommandButton Command3
Caption = "-"
Height = 375
Left = 2520
TabIndex = 11
Top = 960
Width = 495
End
Begin VB.CommandButton Command2
Caption = "+"
Height = 375
Left = 1920
TabIndex = 10
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 375
Index = 9
Left = 1320
TabIndex = 9
Top = 480
Width = 495
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 375
Index = 8
Left = 720
TabIndex = 8
Top = 480
Width = 495
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 375
Index = 7
Left = 120
TabIndex = 7
Top = 480
Width = 495
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 375
Index = 6
Left = 1320
TabIndex = 6
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 375
Index = 5
Left = 720
TabIndex = 5
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 375
Index = 4
Left = 120
TabIndex = 4
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 375
Index = 3
Left = 1320
TabIndex = 3
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 375
Index = 2
Left = 720
TabIndex = 2
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 375
Index = 1
Left = 120
TabIndex = 1
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 375
Index = 0
Left = 720
TabIndex = 0
Top = 1920
Width = 495
End
End
Attribute VB_Name = "frmmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Data As Double
Private lOperation As Long
Private fClear As Boolean
Private Sub cmdDot_Click()
If InStr(1, Text1.Text, ".") <= 0 Then Text1.Text = Text1.Text & "."
End Sub
Private Sub Command1_Click(Index As Integer)
If fClear = True Then Text1.Text = "": fClear = False
Text1.Text = Text1.Text & Index
End Sub
Private Sub Command10_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 5
lblOperation.Caption = "^"
End Sub
Private Sub Command2_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 1
lblOperation.Caption = "+"
End Sub
Private Sub Command3_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 2
lblOperation.Caption = "-"
End Sub
Private Sub Command4_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 3
lblOperation.Caption = "*"
End Sub
Private Sub Command5_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 4
lblOperation.Caption = "/"
End Sub
Private Sub Command6_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command7_Click()
If Val(Text1.Text) <= 0 Then MsgBox "开方数大于等于0"
Text1.Text = Sqr(Val(Text1.Text))
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command8_Click()
Text1.Text = ""
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command9_Click()
If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0"): Command1_Click 0
Case Asc("1"): Command1_Click 1
Case Asc("2"): Command1_Click 2
Case Asc("3"): Command1_Click 3
Case Asc("4"): Command1_Click 5
Case Asc("5"): Command1_Click 4
Case Asc("6"): Command1_Click 6
Case Asc("7"): Command1_Click 7
Case Asc("8"): Command1_Click 8
Case Asc("9"): Command1_Click 9
Case Asc("."): cmdDot_Click
Case Asc("+"): Command2_Click
Case Asc("-"): Command3_Click
Case Asc("*"): Command4_Click
Case Asc("/"): Command5_Click
Case Asc("^"): Command10_Click
Case Asc("s"): Command7_Click
Case Asc("S"): Command7_Click
Case vbKeyBack: Command9_Click
Case Asc("`"): Command8_Click
Case Asc("="): Command6_Click
Case 13: Command6_Click
End Select
KeyAscii = 0
End Sub
VERSION 5.00
Begin VB.Form frmMain
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 3 'Fixed Dialog
Caption = "简单计算器"
ClientHeight = 2430
ClientLeft = 45
ClientTop = 435
ClientWidth = 3150
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2430
ScaleWidth = 3150
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command10
Caption = "^"
Height = 375
Left = 1920
TabIndex = 22
Top = 1920
Width = 495
End
Begin VB.PictureBox picDisplay
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 120
ScaleHeight = 225
ScaleWidth = 2865
TabIndex = 19
Top = 120
Width = 2895
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BorderStyle = 0 'None
Height = 255
Left = 240
Locked = -1 'True
TabIndex = 20
Top = 0
Width = 2535
End
Begin VB.Label lblOperation
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 60
TabIndex = 21
Top = 0
Width = 255
End
End
Begin VB.CommandButton Command9
Caption = "退格"
Height = 375
Left = 1920
TabIndex = 18
Top = 480
Width = 495
End
Begin VB.CommandButton Command8
Caption = "清零"
Height = 375
Left = 2520
TabIndex = 17
Top = 480
Width = 495
End
Begin VB.CommandButton cmdDot
Caption = "."
Height = 375
Left = 120
TabIndex = 16
Top = 1920
Width = 495
End
Begin VB.CommandButton Command7
Caption = "Sqrt"
Height = 375
Left = 2520
TabIndex = 15
Top = 1920
Width = 495
End
Begin VB.CommandButton Command6
Caption = "="
Height = 375
Left = 1320
TabIndex = 14
Top = 1920
Width = 495
End
Begin VB.CommandButton Command5
Caption = "/"
Height = 375
Left = 2520
TabIndex = 13
Top = 1440
Width = 495
End
Begin VB.CommandButton Command4
Caption = "*"
Height = 375
Left = 1920
TabIndex = 12
Top = 1440
Width = 495
End
Begin VB.CommandButton Command3
Caption = "-"
Height = 375
Left = 2520
TabIndex = 11
Top = 960
Width = 495
End
Begin VB.CommandButton Command2
Caption = "+"
Height = 375
Left = 1920
TabIndex = 10
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 375
Index = 9
Left = 1320
TabIndex = 9
Top = 480
Width = 495
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 375
Index = 8
Left = 720
TabIndex = 8
Top = 480
Width = 495
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 375
Index = 7
Left = 120
TabIndex = 7
Top = 480
Width = 495
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 375
Index = 6
Left = 1320
TabIndex = 6
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 375
Index = 5
Left = 720
TabIndex = 5
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 375
Index = 4
Left = 120
TabIndex = 4
Top = 960
Width = 495
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 375
Index = 3
Left = 1320
TabIndex = 3
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 375
Index = 2
Left = 720
TabIndex = 2
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 375
Index = 1
Left = 120
TabIndex = 1
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 375
Index = 0
Left = 720
TabIndex = 0
Top = 1920
Width = 495
End
End
Attribute VB_Name = "frmmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Data As Double
Private lOperation As Long
Private fClear As Boolean
Private Sub cmdDot_Click()
If InStr(1, Text1.Text, ".") <= 0 Then Text1.Text = Text1.Text & "."
End Sub
Private Sub Command1_Click(Index As Integer)
If fClear = True Then Text1.Text = "": fClear = False
Text1.Text = Text1.Text & Index
End Sub
Private Sub Command10_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 5
lblOperation.Caption = "^"
End Sub
Private Sub Command2_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 1
lblOperation.Caption = "+"
End Sub
Private Sub Command3_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 2
lblOperation.Caption = "-"
End Sub
Private Sub Command4_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 3
lblOperation.Caption = "*"
End Sub
Private Sub Command5_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 4
lblOperation.Caption = "/"
End Sub
Private Sub Command6_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command7_Click()
If Val(Text1.Text) <= 0 Then MsgBox "开方数大于等于0"
Text1.Text = Sqr(Val(Text1.Text))
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command8_Click()
Text1.Text = ""
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command9_Click()
If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0"): Command1_Click 0
Case Asc("1"): Command1_Click 1
Case Asc("2"): Command1_Click 2
Case Asc("3"): Command1_Click 3
Case Asc("4"): Command1_Click 5
Case Asc("5"): Command1_Click 4
Case Asc("6"): Command1_Click 6
Case Asc("7"): Command1_Click 7
Case Asc("8"): Command1_Click 8
Case Asc("9"): Command1_Click 9
Case Asc("."): cmdDot_Click
Case Asc("+"): Command2_Click
Case Asc("-"): Command3_Click
Case Asc("*"): Command4_Click
Case Asc("/"): Command5_Click
Case Asc("^"): Command10_Click
Case Asc("s"): Command7_Click
Case Asc("S"): Command7_Click
Case vbKeyBack: Command9_Click
Case Asc("`"): Command8_Click
Case Asc("="): Command6_Click
Case 13: Command6_Click
End Select
KeyAscii = 0
End Sub
展开全部
Private Sub Command1_Click()
Static i As Integer
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' 定义信息。
Style = vbYesNo + vbCritical + vbDefaultButton2 ' 定义按钮。
Title = "MsgBox Demonstration" ' 定义标题。
Help = "DEMO.HLP" ' 定义帮助文件。
Ctxt = 1000 ' 定义标题
i = i + 1
Select Case i
Case 1
Command1.Caption = "1"
Case 2
Command1.Caption = "22"
Case 3
Command1.Caption = "33"
Case Else
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' 用户按下“是”。
MyString = "Yes" ' 完成某操作。
Else ' 用户按下“否”。
MyString = "No" ' 完成某操作。
End If
End Select
End Sub
Static i As Integer
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' 定义信息。
Style = vbYesNo + vbCritical + vbDefaultButton2 ' 定义按钮。
Title = "MsgBox Demonstration" ' 定义标题。
Help = "DEMO.HLP" ' 定义帮助文件。
Ctxt = 1000 ' 定义标题
i = i + 1
Select Case i
Case 1
Command1.Caption = "1"
Case 2
Command1.Caption = "22"
Case 3
Command1.Caption = "33"
Case Else
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' 用户按下“是”。
MyString = "Yes" ' 完成某操作。
Else ' 用户按下“否”。
MyString = "No" ' 完成某操作。
End If
End Select
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Dim i As Integer
Private Sub Command1_Click()
Select Case i
Case 1
Command1.Caption = 1
i = i + 1
Case 2 To 3
Command1.Caption = i * 10 + i
i = i + 1
Case 4
' If MsgBox("是否执行程序?", vbYesNo, "询问") = vbYes Then
' ……………………
' Else
' ……………………
' End If
End Select
End Sub
Private Sub Form_Load()
i = 1
End Sub
Dim i As Integer
Private Sub Command1_Click()
Select Case i
Case 1
Command1.Caption = 1
i = i + 1
Case 2 To 3
Command1.Caption = i * 10 + i
i = i + 1
Case 4
' If MsgBox("是否执行程序?", vbYesNo, "询问") = vbYes Then
' ……………………
' Else
' ……………………
' End If
End Select
End Sub
Private Sub Form_Load()
i = 1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-03-25
展开全部
我晕咋都和题目不一样,小弟借用参考下.呵呵!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询