5 Replies - 430 Views - Last Post: 10 October 2012 - 07:00 AM Rate Topic: -----

#1 wanabavbcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-October 12

Checkedbox value to be saved as a variable

Posted 09 October 2012 - 03:28 PM

I understand that the declaration is within the if...then tags but how can I make sure that when the checkedbox is checked and assign it a variable to use in the later on in my code? Totally stumped. This is what I have managed to pull out of my grey matter. lol.
If CheckBox1.Checked Then
            Dim toi = "Toilets"
            CheckBox1.Text = toi
            TextBox7.Text = toi.ToString
        End If
        If CheckBox2.Checked Then
            Dim park = "Parking"
            CheckBox2.Text = park
        End If
        If CheckBox3.Checked Then
            Dim decore = "Decore"
            CheckBox3.Text = decore
        End If
        If CheckBox4.Checked Then
            Dim food = "Catering"
            CheckBox4.Text = food
        End If
        If CheckBox5.Checked Then
            Dim cool = "Air Conditioning"
            CheckBox5.Text = cool
        End If


Is This A Good Question/Topic? 0
  • +

Replies To: Checkedbox value to be saved as a variable

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9502
  • View blog
  • Posts: 35,850
  • Joined: 12-June 08

Re: Checkedbox value to be saved as a variable

Posted 09 October 2012 - 06:00 PM

What's the data type of a the checkbox's "checked" property? Boolean! Store it in one of those!
Was This Post Helpful? 0
  • +
  • -

#3 wanabavbcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-October 12

Re: Checkedbox value to be saved as a variable

Posted 09 October 2012 - 10:22 PM

I am assuming they are boolean. But where I am struggling is, to assign a variable example:
!!!NOTE THIS IS NOT CODE BUT SIMPLY A WAY FOR ME TO EXPLAIN BETTER!!!!

DIM var as string
where if checkbox1.checked then save the value to var
and if not checked then do nothing.
code...code...

display var to label1

end sub

I just need the user of the program to know which of the checkboxs was checked. I need to save to a database and display later in the program
I hope you understand what I am trying to say

This post has been edited by wanabavbcoder: 09 October 2012 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9502
  • View blog
  • Posts: 35,850
  • Joined: 12-June 08

Re: Checkedbox value to be saved as a variable

Posted 09 October 2012 - 11:19 PM

Having the values stored in a variable is one thing - making the connection to a database is another.

dim bVal as boolean = false

bVal = checkbox1.checked



There are DB tutorials in the VB.NET tutorial section if you want to do the latter.
Was This Post Helpful? 1
  • +
  • -

#5 wanabavbcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-October 12

Re: Checkedbox value to be saved as a variable

Posted 10 October 2012 - 12:14 AM

okay that is awesome.
Dim bVal As boolean = False
        bVal = CheckBox1.Checked

NO ERRORS!
so now how would my program know that when the box is checked that it must save bVal as Toilets.
My goal is to assign 5 variables for 5 checkboxes.
when the checkboxes is checked then i need to display the values of the all the checkboxes that are checked in a label and leave out the ones that are unchecked.

The database part is covered. But thanks for the tip. I will have a go at it.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9502
  • View blog
  • Posts: 35,850
  • Joined: 12-June 08

Re: Checkedbox value to be saved as a variable

Posted 10 October 2012 - 07:00 AM

Quote

so now how would my program know that when the box is checked that it must save bVal as Toilets.

Check the events man! Each checkbox has a 'check changed' event. Set it up an inside each set a boolean variable to the value of the checkbox.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1