Welcome to Dream.In.Code
Become a VB Expert!

Join 137,233 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,791 people online right now. Registration is fast and FREE... Join Now!




Checkboxes in VB.NET

 
Reply to this topicStart new topic

Checkboxes in VB.NET, Beginner stuff

sierra
9 Mar, 2007 - 01:04 PM
Post #1

New D.I.C Head
*

Joined: 9 Mar, 2007
Posts: 1


My Contributions
I'm not looking for anyone to hand me the coding, but if someone could just start me off in the right direction, I would appreciate it.

Very beginner stuff..

I have 10 check boxes, each with the name of a different color (shirts). If the user selects one box, the total price should show up in a box as $5.00. If they select two checkboxes, the price (of two shirts) should read $9.00.

I'm stuck on how I would go about adding checkboxes together. Can anyone help me? I don't have any coding so far for that part of the program.. I'm not sure where to even begin. crazy.gif

edit: modified title ~ jayman9
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Checkboxes In VB.NET
9 Mar, 2007 - 02:15 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You will need a variable to store the total price for each item that is selected. Then as boxes are checked or unchecked you will increase/decrease the total price stored in that variable.
User is online!Profile CardPM
+Quote Post

m2s87
RE: Checkboxes In VB.NET
9 Mar, 2007 - 05:33 PM
Post #3

D.I.C Regular
Group Icon

Joined: 28 Nov, 2006
Posts: 390



Thanked: 1 times
Dream Kudos: 1225
My Contributions
QUOTE(sierra @ 9 Mar, 2007 - 11:04 PM) *

I'm not looking for anyone to hand me the coding, but if someone could just start me off in the right direction, I would appreciate it.

Very beginner stuff..

I have 10 check boxes, each with the name of a different color (shirts). If the user selects one box, the total price should show up in a box as $5.00. If they select two checkboxes, the price (of two shirts) should read $9.00.

I'm stuck on how I would go about adding checkboxes together. Can anyone help me? I don't have any coding so far for that part of the program.. I'm not sure where to even begin. crazy.gif

edit: modified title ~ jayman9

You cam make an event based solution, something like:
CODE

private changevalue(a as object, b as error) handles checkbox1.checked, checkbox2.checked, checkbox3.checked 'and on, ...
   const MyDiscount as float=0.9F
   const TshirtPrice as float=5.0F
   dim total as integer=0
  
   if checkbox0.checked=true then total+=1
   if checkbox1.checked=true then total+=1
   if checkbox2.checked=true then total+=1
   if checkbox3.checked=true then total+=1
   if checkbox4.checked=true then total+=1
   if checkbox5.checked=true then total+=1
   if checkbox6.checked=true then total+=1
   if checkbox7.checked=true then total+=1
   if checkbox8.checked=true then total+=1
   if checkbox8.checked=true then total+=1

   price.txt=FormatCurrency(total*TshirtPrice*iif(total>1,MyDiscount^(total-1),1))
end sub

User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: Checkboxes In VB.NET
11 Mar, 2007 - 08:42 AM
Post #4

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
heres an eaiser code to understand
CODE

dim firstshirt as boolean
dim 2ndshirt
if checkbox1.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox2.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox3.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox4.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox5.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox6.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox7.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox8.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox9.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if checkbox10.checked = true then
if firstshirt = true then
2ndshirt = true
end if
end if

if firstshirt = true then
msgbox("5 dollars")
end if
if 2ndshirt = true then
msgbox("9 dollars")
end if
end sub



This post has been edited by orangeslide8: 11 Mar, 2007 - 08:42 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Checkboxes In VB.NET
11 Mar, 2007 - 09:08 AM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Perhaps easier to understand, but slightly less efficient. As your if statements appear to be self contained, it may be better to use a multiple condition with the AND operator than have a separate if statement inside each.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:39PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month