vb 复选框用法
三个复选框一个命令按钮一个文本框,当选中复选框后单击命令按钮文本中输出复选框的标题,但不断的单击命令按钮又不断输出重复的内容,而且然后取消复选框选择后再单击命令按钮区无法...
三个复选框一个命令按钮一个文本框,当选中复选框后单击命令按钮文本中输出复选框的标题,但不断的单击命令按钮又不断输出重复的内容,而且然后取消复选框选择后再单击命令按钮区无法取消,请问高手如何处理?(一个初学者)
展开
7个回答
推荐于2016-08-07 · 知道合伙人软件行家
关注
展开全部
CheckBox 控件
组中可以使用 CheckBox 控件显示多项选择,从而可选择其中的一项或多项。也可以通过对 Value 属性编程设置
CheckBox 的值。
在一个窗体中可以同时选择任意数量的 CheckBox 控件。
以下代码会告诉CheckBox 控件单选或多选的状态
Option Explicit
Private Sub Check1_Click()
Debug.Print Check1.Value; Check2.Value; Check3.Value
End Sub
Private Sub Check2_Click()
Debug.Print Check1.Value; Check2.Value; Check3.Value
End Sub
Private Sub Check3_Click()
Debug.Print Check1.Value; Check2.Value; Check3.Value
End Sub
展开全部
想提醒楼上的:你的事件用的不对,
应为private
sub
check1_click()
,还有value的属性值不对,应为
0、1、2,而不是1、2、3,其中“0”意为未选中,“1”意为选中,“2”意为无效。
创建一个组check1(0)、check1(1)、check1(2).
应为private
sub
check1_click()
,还有value的属性值不对,应为
0、1、2,而不是1、2、3,其中“0”意为未选中,“1”意为选中,“2”意为无效。
创建一个组check1(0)、check1(1)、check1(2).
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
答案修改:原来如此啊。以下是修改完毕的代码。
建command1,command2,command3,command4,check1,check2,check3.
================
Sub
Run()
If
Check1.Value
=
vbChecked
Then
Open
"c:\test\file1.txt"
For
Output
As
1
Print
#1,
InputBox("A")
Close
End
If
If
Check2.Value
=
vbChecked
Then
Open
"c:\test\file2.txt"
For
Output
As
2
Print
#2,
InputBox("B")
Close
End
If
If
Check3.Value
=
vbChecked
Then
Open
"c:\test\file3.txt"
For
Output
As
3
Print
#3,
InputBox("C")
Close
End
If
End
Sub
Private
Sub
Command1_Click()
Check1.Value
=
vbChecked
Check2.Value
=
vbChecked
Check3.Value
=
vbUnchecked
End
Sub
Private
Sub
Command2_Click()
Run
MsgBox
"执行完毕"
End
Sub
Private
Sub
Command3_Click()
End
End
Sub
Private
Sub
Command4_Click()
Run
Command1_Click
MsgBox
"已还原"
End
Sub
Private
Sub
Form_Load()
Command1.Caption
=
"默认"
Command2.Caption
=
"确定"
Command3.Caption
=
"取消"
Command4.Caption
=
"还原"
Check1.Caption
=
"A"
Check2.Caption
=
"B"
Check3.Caption
=
"C"
Check1.Value
=
vbChecked
Check2.Value
=
vbChecked
End
Sub
建command1,command2,command3,command4,check1,check2,check3.
================
Sub
Run()
If
Check1.Value
=
vbChecked
Then
Open
"c:\test\file1.txt"
For
Output
As
1
#1,
InputBox("A")
Close
End
If
If
Check2.Value
=
vbChecked
Then
Open
"c:\test\file2.txt"
For
Output
As
2
#2,
InputBox("B")
Close
End
If
If
Check3.Value
=
vbChecked
Then
Open
"c:\test\file3.txt"
For
Output
As
3
#3,
InputBox("C")
Close
End
If
End
Sub
Private
Sub
Command1_Click()
Check1.Value
=
vbChecked
Check2.Value
=
vbChecked
Check3.Value
=
vbUnchecked
End
Sub
Private
Sub
Command2_Click()
Run
MsgBox
"执行完毕"
End
Sub
Private
Sub
Command3_Click()
End
End
Sub
Private
Sub
Command4_Click()
Run
Command1_Click
MsgBox
"已还原"
End
Sub
Private
Sub
Form_Load()
Command1.Caption
=
"默认"
Command2.Caption
=
"确定"
Command3.Caption
=
"取消"
Command4.Caption
=
"还原"
Check1.Caption
=
"A"
Check2.Caption
=
"B"
Check3.Caption
=
"C"
Check1.Value
=
vbChecked
Check2.Value
=
vbChecked
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有明白你的意思,我看懂的就是这些了,不好意思:
Dim a As Long
Private Sub Command1_Click()
a = Check1.Value
Select Case a
Case 1
Text1.Text = Check1.Caption
Case 0
Text1.Text = ""
End Select
End Sub
没有像你说的那样取消不了
Dim a As Long
Private Sub Command1_Click()
a = Check1.Value
Select Case a
Case 1
Text1.Text = Check1.Caption
Case 0
Text1.Text = ""
End Select
End Sub
没有像你说的那样取消不了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim 判断1 As Boolean, 判断2 As Boolean, 判断3 As Boolean
Private Sub Check1_Click()
If Check1.Value = 1 Then 判断1 = True
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then 判断2 = True
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then 判断3 = True
End Sub
Private Sub Command1_Click()
If 判断1 = True Then Text1.Text = Text1.Text & Check1.Caption
If 判断2 = True Then Text1.Text = Text1.Text & Check2.Caption
If 判断3 = True Then Text1.Text = Text1.Text & Check3.Caption
End Sub
Private Sub Form_Load()
判断1 = fasle
判断2 = fasle
判断3 = fasle
End Sub
Private Sub Check1_Click()
If Check1.Value = 1 Then 判断1 = True
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then 判断2 = True
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then 判断3 = True
End Sub
Private Sub Command1_Click()
If 判断1 = True Then Text1.Text = Text1.Text & Check1.Caption
If 判断2 = True Then Text1.Text = Text1.Text & Check2.Caption
If 判断3 = True Then Text1.Text = Text1.Text & Check3.Caption
End Sub
Private Sub Form_Load()
判断1 = fasle
判断2 = fasle
判断3 = fasle
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询