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?
Check box codes
Collapse
X
-
-
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? -
Originally posted by Killer42Hm... 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
-
Originally posted by bupandahm.. 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 SubComment
-
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
DanComment
-
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.Comment
-
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
-
Originally posted by dbanningVb 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
just a thought, is there any other ways i can do it besides using the If statement?Comment
-
Originally posted by bupandaOkay, it works now thanks a lot :)
just a thought, is there any other ways i can do it besides using the If statement?
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
-
Originally posted by Tig201in the checkbox_click( ) ad the following
Code:label.Visible = checkbox.value
surly you will just get an errorComment
Comment