回 帖 发 新 帖 刷新版面

主题:帮忙解释下这段话  =(简单 可我不会!!)

这个vb程序 ,有5个复选框,和1个按钮。



Private Sub Command1_Click()
  Dim note
  If Check1.Value = 1 Then note = Check1.Caption
  If Check2.Value = 1 Then note = note & " " & Check2.Caption
  If Check3.Value = 1 Then note = note & " " & Check3.Caption
  If Check4.Value = 1 Then note = note & " " & Check4.Caption
  If Check5.Value = 1 Then note = note & " " & Check5.Caption
  MsgBox "您选择的是: " & note
End Sub

要求解释这几句中  第2个等于号 后面的note & " " & Check2.Caption 含义

  If Check1.Value = 1 Then note = Check1.Caption
  If Check2.Value = 1 Then note = note & " " & Check2.Caption
  If Check3.Value = 1 Then note = note & " " & Check3.Caption
  If Check4.Value = 1 Then note = note & " " & Check4.Caption
  If Check5.Value = 1 Then note = note & " " & Check5.Caption 

回复列表 (共3个回复)

沙发


note & " " & Check2.Caption 就是你选择的控件

板凳

这几句的作用,是把被选中的复选框标题累加,举个例说,如果这5个复选框的标题分别是:编、程、爱、好、者,那么:

If Check1.Value = 1 Then note = Check1.Caption              'note="编"
If Check2.Value = 1 Then note = note & " " & Check2.Caption 'note="编"+" 程"="编 程"
If Check3.Value = 1 Then note = note & " " & Check3.Caption 'note="编 程"+" 爱"="编 程 爱"
If Check4.Value = 1 Then note = note & " " & Check4.Caption 'note="编 程 爱"+" 好"="编 程 爱 好"
If Check5.Value = 1 Then note = note & " " & Check5.Caption 'note="编 程 爱 好"+" 者"="编 程 爱 好 者"

3 楼

补充一点,(在一江秋水的假设之上)
如果你5个全选,就如一江秋水所说。
如果你选了第一个、第三个、第五个,结果则是:
If Check1.Value = 1 Then note = Check1.Caption              'note="编"
If Check2.Value = 1 Then note = note & " " & Check2.Caption 'note="编"
If Check3.Value = 1 Then note = note & " " & Check3.Caption 'note="编"+" 爱"="编 爱"
If Check4.Value = 1 Then note = note & " " & Check4.Caption 'note="编 爱"
If Check5.Value = 1 Then note = note & " " & Check5.Caption 'note="编 爱"+" 者"="编 爱 者"
其他情况以此类推

我来回复

您尚未登录,请登录后再回复。点此登录或注册