VB6 Data table

Posted on 2006-04-08
Last Modified: 2006-11-18
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!

Question by:NewsInternationalLtd
    LVL 3

    Expert Comment

    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

    Expert Comment

    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)


    Author Comment

    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.

    Accepted Solution

    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

    Author Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now