473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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?
Apr 17 '07 #1
17 16125
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
Killer42
8,435 Expert 8TB
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
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
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
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
103 100+
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
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
103 100+
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
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
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
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
103 100+
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
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
103 100+
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
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
Killer42
8,435 Expert 8TB
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
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

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

Similar topics

3
by: Hari Om | last post by:
Hi ORAPERTS (ORAcle xPERTS) How can I define a CHECK CONSTRAINT on a table for a field like zip code....? Here is what I am doing: create table test ( state varchar2(5) check (state...
2
by: Phil Green | last post by:
Hi, I have been creating a CD-based site which works exactly how I want in IE5. I decided that I should test it in Mozilla Firefox and Opera. Unfortunately, a lot of the scrips don't work as...
6
by: test2000 | last post by:
Hello I'm trying to write a javascript that checks if a server/host is available. To be more precice. I would like to check if the browser can read an XML file from a server. If not the script...
71
ChaseCox
by: ChaseCox | last post by:
I would like to use a Check Box, or several check boxes, that will allow a user to select differnent product lines. The user should be able to select one or many. I also need each check box to...
2
by: bupanda | last post by:
I need to write codes in visual basic for check boxes that "Allow the user choose to display or hide the title, the country name, and the name of the programmer. Use check boxes for the display/hide...
2
butro
by: butro | last post by:
I have a form which can check whether is an image or not. But when i try to choose a real image whose name include more than one "." character, the script fails. The split function can not be detect...
9
by: eggie5 | last post by:
How would I check if a string is a number? e.g: 'asdf2' =false '34' =true 'asf' =false '0' =true
1
by: RapSmurf | last post by:
Hellow I am using an free Flatcast Radio streaming on my site. Located at: http://www.flatcast.com I have searched alot to find an answer for the next question !! Is it possible to chek if...
5
by: =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post by:
Hi, I would like to have someone comments on what's the best practice defining error codes in C. Here's what I think: solution A: using enum pros: type safe. better for debug (some debugger...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.