Check box codes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bupanda
    New Member
    • Apr 2007
    • 7

    Check box codes

    How do i write codes in visual basic for check boxes that allow the user to choose to display or hide the the lables without using the if statement?
  • bupanda
    New Member
    • Apr 2007
    • 7

    #2
    I wrote chkTitle.Value = 1
    lblTitle.Captio n = ""

    and now when it is in the Run mode, when I check the box the lblTitle.Captio n disappears as I wish

    but what should i write so that when i uncheck it (chk.Title.Valu e = 0) , my lblTitle.Captio n = whatever it was...?


    i tried to write chkTitle.Value = 0 rigth under lblTitle.Captio n = " " but it doesnt work .. says run time error "28"

    can anyone help me?

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Hm... don't think I didn't notice the re-posting of the same question. :(

      However, since you seem to be making an effort at doing the work yourself, here's a suggestion... try changing the visibility, rather than the text.

      Comment

      • bupanda
        New Member
        • Apr 2007
        • 7

        #4
        Originally posted by Killer42
        Hm... don't think I didn't notice the re-posting of the same question. :(

        However, since you seem to be making an effort at doing the work yourself, here's a suggestion... try changing the visibility, rather than the text.

        hm.. okay so
        chkTitle.Value = 1
        lblTitle.Visibl e = False
        this works too but My problem is that once i checked it and the Title dissapears I cannot uncheck it... and I dont know how should I put both code together... tried with
        chkTitle.Value = 1
        lblTitle.Visibl e = False
        chkTitle.Value = 0
        lblTitle.Visibl e = True
        but doesnt work..Thanks for the help :)

        Comment

        • bupanda
          New Member
          • Apr 2007
          • 7

          #5
          Originally posted by bupanda
          hm.. okay so
          chkTitle.Value = 1
          lblTitle.Visibl e = False
          this works too but My problem is that once i checked it and the Title dissapears I cannot uncheck it... and I dont know how should I put both code together... tried with
          chkTitle.Value = 1
          lblTitle.Visibl e = False
          chkTitle.Value = 0
          lblTitle.Visibl e = True
          but doesnt work..Thanks for the help :)

          Yeah.. this is the most I can think of at the moment ...

          Private Sub chkTitle_Click( )
          'Display or Hide the Title

          chkTitle.Value = 1 <-- This one works perfectly fine
          lblTitle.Visibl e = False

          chkTitle.Value = 0 <---- this is where my problem is but I dont know
          lblTitle.Visibl e = True why I cannot do it like this...
          shows run-time error '28'; out of stack place
          End Sub



          End Sub

          Comment

          • dbanning
            New Member
            • Apr 2007
            • 19

            #6
            Vb will work its way down you statements from top to bottom you asking check title value has no relation to the the title disapering

            If I understand you correctly you need an if statement to get it to work.

            Eg

            If chkTitle.Value = 1 then
            lblTitle.Visibl e = False
            else
            lblTitle.Visibl e = True
            end if

            Dan

            Comment

            • Tig201
              New Member
              • Mar 2007
              • 103

              #7
              Just a thought but wouldn't the value of the checkbox be true or false and that is what you want your labels visibility state to be?

              Comment

              • dbanning
                New Member
                • Apr 2007
                • 19

                #8
                check boxes can either be value 0,2,1 meaning unchecked, greyed or checked.

                Thats what I'm aware of and the method I use setting ture and false might work but I would guess not as there are three possible variables and not two.
                Last edited by dbanning; Apr 17 '07, 07:10 PM. Reason: Mistake

                Comment

                • Tig201
                  New Member
                  • Mar 2007
                  • 103

                  #9
                  if a check box is set to grayed (value 2) and the user clicks the check box it becomes unchecked (Value 0) if they click it again it becomes checked (Value 1) @ this point the user can not change the value of the check box to anything other than checked or unchecked by clicking on the check box at least not in VB6.

                  Comment

                  • dbanning
                    New Member
                    • Apr 2007
                    • 19

                    #10
                    This is true its just a third variable that you can set up incase you require it. There is some way to enable it but I can not remember how not a control I use regularly.

                    It would be useful in logic calculations which is probably what it meant for.

                    Comment

                    • bupanda
                      New Member
                      • Apr 2007
                      • 7

                      #11
                      Originally posted by dbanning
                      Vb will work its way down you statements from top to bottom you asking check title value has no relation to the the title disapering

                      If I understand you correctly you need an if statement to get it to work.

                      Eg

                      If chkTitle.Value = 1 then
                      lblTitle.Visibl e = False
                      else
                      lblTitle.Visibl e = True
                      end if

                      Dan
                      Okay, it works now thanks a lot :)
                      just a thought, is there any other ways i can do it besides using the If statement?

                      Comment

                      • dbanning
                        New Member
                        • Apr 2007
                        • 19

                        #12
                        Originally posted by bupanda
                        Okay, it works now thanks a lot :)
                        just a thought, is there any other ways i can do it besides using the If statement?
                        For what you wanted to do not really that is the easiest way to do it.

                        You original code failed as you required the label to change value only when another item changed in this case the cheack box.

                        It is therefore a conditional statement the if statement does something if this condition is met so if your checkbox was 1 meaning checked it does the statement below if it wasn't so either a 0 or 2 meaning unchecked and grayed then is does the else statment.

                        If there is something specific you are thinking off other than this let me know and i will try to help.

                        Comment

                        • Tig201
                          New Member
                          • Mar 2007
                          • 103

                          #13
                          in the checkbox_click( ) ad the following
                          Code:
                          label.Visible = checkbox.value
                          Don't forget to set the checkbox's initial value to checked or the labels Visible state to false.

                          Comment

                          • dbanning
                            New Member
                            • Apr 2007
                            • 19

                            #14
                            Originally posted by Tig201
                            in the checkbox_click( ) ad the following
                            Code:
                            label.Visible = checkbox.value
                            Don't forget to set the checkbox's initial value to checked or the labels Visible state to false.
                            Not sure how this will work you are saying that label.visible can either be 1 or 0 but visible areguments can either be true or false?

                            surly you will just get an error

                            Comment

                            • Tig201
                              New Member
                              • Mar 2007
                              • 103

                              #15
                              remeber a boolean can only handle two values true or false these can be represented by 0 = false and any other number = True

                              Comment

                              Working...