By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Check box codes

P: 7
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?
Apr 17 '07 #1
Share this Question
Share on Google+
17 Replies


P: 7
I wrote chkTitle.Value = 1
lblTitle.Caption = ""

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

but what should i write so that when i uncheck it (chk.Title.Value = 0) , my lblTitle.Caption = whatever it was...?


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

can anyone help me?
Apr 17 '07 #2

Expert 5K+
P: 8,434
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.
Apr 17 '07 #3

P: 7
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.Visible = 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.Visible = False
chkTitle.Value = 0
lblTitle.Visible = True
but doesnt work..Thanks for the help :)
Apr 17 '07 #4

P: 7
hm.. okay so
chkTitle.Value = 1
lblTitle.Visible = 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.Visible = False
chkTitle.Value = 0
lblTitle.Visible = 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.Visible = False

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



End Sub
Apr 17 '07 #5

dbanning
P: 19
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.Visible = False
else
lblTitle.Visible = True
end if

Dan
Apr 17 '07 #6

Tig201
100+
P: 103
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?
Apr 17 '07 #7

dbanning
P: 19
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.
Apr 17 '07 #8

Tig201
100+
P: 103
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.
Apr 17 '07 #9

dbanning
P: 19
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.
Apr 17 '07 #10

P: 7
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.Visible = False
else
lblTitle.Visible = 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?
Apr 17 '07 #11

dbanning
P: 19
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.
Apr 17 '07 #12

Tig201
100+
P: 103
in the checkbox_click() ad the following
Expand|Select|Wrap|Line Numbers
  1. label.Visible = checkbox.value
Don't forget to set the checkbox's initial value to checked or the labels Visible state to false.
Apr 17 '07 #13

dbanning
P: 19
in the checkbox_click() ad the following
Expand|Select|Wrap|Line Numbers
  1. 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
Apr 17 '07 #14

Tig201
100+
P: 103
remeber a boolean can only handle two values true or false these can be represented by 0 = false and any other number = True
Apr 17 '07 #15

dbanning
P: 19
remeber a boolean can only handle two values true or false these can be represented by 0 = false and any other number = True
Thats true good code perhaps you can answer my post that im stuck with.

http://www.thescripts.com/forum/thread633852.html

any help would be good
Apr 17 '07 #16

Expert 5K+
P: 8,434
bupanda, I just wanted to check - do you understand why you got that stack overflow error?

It's probably not something you need to worry about now since it is now longer happening, but I believe it's fairly important in building an understanding of how this sort of event-driven code works, and will help you later.

Oh, and another thing. If you really need to avoid the IF statement (which seems odd) I can think of a couple of alternatives. One is the Select Case statement, but that's probably further ahead of your current subject than IF. Another would be to simply "toggle" the visibility of the label - that is, every time the checkbox is clicked, regardless of the value, just switch the visibility property to the opposite of what it is now. That ought to do the trick.
Apr 17 '07 #17

P: 2
You all made this way to difficult.

NAMEOFLABEL.Visible = NAMEOFCHECKBOX.CheckState

Then just make sure that the checkbox is checked at start up and the label is set to visible.

When you toggle the checkbox, the label will disappear and reappear with it.

No if statement required, you could use one, its just extra code.
Sep 13 '13 #18

Post your reply

Sign in to post your reply or Sign up for a free account.