Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

VB6 Data table

I have created a vb6 app which consists of a form with 4 application titles and 2 checkboxes next to each title. What I need is a way to trigger certain events based on what checkboxes are ticked, eg

chk1 ticked, chk2 clear > set action1
chk1 ticked, chk2 ticked > set action2
chk1 clear, chk2 clear > set action3

What I am looking for is an elegant solution that avoids a whole bunch of If...Then statements. Part of the reason I need this is because I would like a msgbox to pop up to explain to the user that they have requested X action with Application1, Y action with application2 and Z action with application3 before commencing and and acting on the request.
Sounds fairly straightforward but I have been struggling to think of a way to do this that I'm happy with!

Your thoughts and suggestions are appreciated as always!

  • 2
  • 2
1 Solution
Try this, I have choosen On Click, but you can use it whenever you want

two check boxes

Private Sub Check1_Click()
    If Check1.Value = 1 And Check2.Value = 0 Then
        MsgBox "First checked, second not"
    ElseIf Check1.Value = 1 And Check2.Value = 1 Then
        MsgBox "Both checked"
    ElseIf Check1.Value = 0 And Check2.Value = 0 Then
        MsgBox "Both Not checked"
    End If
End Sub
select case Check.1 + 2* Check.2
  case 0
  case 1
  case 2
    MsgBox "Not possible to check 2 and not 1"
  case 3
    action 2
end select

Of course, this is expandable to more check boxes (+ 4*Check.3 + 8*Check.4)

NewsInternationalLtdAuthor Commented:
The first solution is the way I have it at present.
I am intrigued by the second though.

Supposing the checkboxes are called AppOffice and AppFP. What is the syntax used for this? I'm trying to figure out exactly how it works.
True has a value of -1 and false is 0; so:

Select Case AppOffice.Value + 2*AppFP.Value
  Case -1
    MsgBox ("You have selected Office")
  Case -2
    MsgBox ("You have selected FP")
  Case -3
    MsgBox ("You have selected both Office and FP")
  Case Else
    MsgBox ("Don't just stand there; do something") ' Put in what you want
End Select
NewsInternationalLtdAuthor Commented:
Excellent, this is what I was looking for. However I would point out that the Case statements create a values of 1, 2, or 3 rather than their negetives. Still, the same principle so thanks.


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now