Groupbox control reference
Groupbox control reference
Groupbox control reference
Groupbox control reference
Groupbox control reference
Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference
Groupbox control reference Groupbox control reference
Groupbox control reference
Go Back  Xtreme Visual Basic Talk > > > Groupbox control reference


Reply
 
Thread Tools Display Modes
  #1  
Old 01-01-2011, 11:06 PM
Cruzersoul Cruzersoul is offline
Newcomer
 
Join Date: Jan 2011
Posts: 2
Default Groupbox control reference


I am extremely knew to Visual Basic and I seem to be stuck. I am writing an application and I do not know how to reference a group of controls inside a group box. I will include the code I have written so far and a picture with a detailed explanation as to what I am trying to do. Feel free to comment on any discrepancies that you may notice in my code.

Thanks for the help.
Code:
Public Class Form1

    ' The following class-level constants are used
    ' to calculate the price of the model

    Const decCOUPE As Decimal = 18000
    Const decSEDAN As Decimal = 19500
    Const decHATCHBACK As Decimal = 18500
    Const decCONVERTIBLE As Decimal = 22500

    ' The following class-level constants are used
    ' to calculate the price of user selected options

    Const decV6 As Decimal = 2537
    Const decSUNROOF As Decimal = 1512
    Const decRADIO As Decimal = 597
    Const decALLOY_WHEELS As Decimal = 3572
    Const decBACKUP_SENSOR As Decimal = 513
    Const decREMOTE_START As Decimal = 532

    ' The following class-level constants are used 
    ' to calculate transmission cost

    Const decAUTO_TRANS As Decimal = 813
    Const decMANUAL_TRANS As Decimal = 0

    ' The following class level constants are used
    ' to calculate discounts

    Const decOPTIONS_DISCOUNT_1TO2 As Decimal = 0.03D
    Const decOPTIONS_DISCOUNT_3TO5 As Decimal = 0.05D
    Const decOPTIONS_DISCOUNT_6 As Decimal = 0.07D

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        ' This method calculate and displays the price of the vehicle

        Dim DecBasePrice As Decimal
        Dim DecTransmissionPrice As Decimal
        Dim DecOptionsPrice As Decimal
        Dim DecSubtotal As Decimal
        Dim DecDiscount As Decimal
        Dim DecTotalPrice As Decimal
        Dim intOptions As Integer

        'Calculate the base price

        If radCoupe.Checked Then
            DecBasePrice = decCOUPE
        ElseIf radSedan.Checked Then
            DecBasePrice = decSEDAN
        ElseIf radHatchback.Checked Then
            DecBasePrice = decHATCHBACK
        ElseIf radConvertible.Checked Then
            DecBasePrice = decCONVERTIBLE
        End If

        'Determine user added options charges

        If chkV6.Checked Then
            DecOptionsPrice += decV6
        End If

        If chkSunroof.Checked Then
            DecOptionsPrice += decSUNROOF
        End If

        If chkSatRadio.Checked Then
            DecOptionsPrice += decRADIO
        End If

        If chkAlloyWheels.Checked Then
            DecOptionsPrice += decALLOY_WHEELS
        End If

        If chkBackupSensor.Checked Then
            DecOptionsPrice += decBACKUP_SENSOR
        End If

        If chkRemoteStart.Checked Then
            DecOptionsPrice += decREMOTE_START
        End If

        'Determine transmission charges

        If radManual.Checked Then
            DecTransmissionPrice += decMANUAL_TRANS
        ElseIf radAutomatic.Checked Then
            DecTransmissionPrice += decAUTO_TRANS
        End If

        ' Determine the discount based upon the
        ' number of user selected options

        Select Case DecDiscount
            Case Is >= 1
                DecDiscount = 0
            Case 1 To 2
                DecDiscount = DecBasePrice * decOPTIONS_DISCOUNT_1TO2
            Case 3 To 5
                DecDiscount = DecBasePrice * decOPTIONS_DISCOUNT_3TO5
            Case Is = 6
                DecDiscount = DecBasePrice * decOPTIONS_DISCOUNT_6

        End Select

        'Display the base price
        lblBasePrice.Text = DecBasePrice.ToString("c")

        'Display the transmission price
        lblTransmission.Text = DecTransmissionPrice.ToString("c")

        'Display the price of the user added options
        lblOptions.Text = DecOptionsPrice.ToString("c")

        'Calculate and display the subtotal
        lblSubtotal.Text = (DecBasePrice + DecTransmissionPrice + DecOptionsPrice).ToString("c")



  
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

        'Clear the form

        'Reset The Buttons
        radCoupe.Checked = True
        radManual.Checked = True

        'Clear the Check Boxes
        chkV6.Checked = False
        chkSunroof.Checked = False
        chkSatRadio.Checked = False
        chkAlloyWheels.Checked = False
        chkBackupSensor.Checked = False
        chkRemoteStart.Checked = False

        'Clear the labels
        lblSelectedOptions.Text = String.Empty
        lblDiscount.Text = String.Empty
        lblBasePrice.Text = String.Empty
        lblTransmission.Text = String.Empty
        lblOptions.Text = String.Empty
        lblSubtotal.Text = String.Empty
        lblDiscountEarned.Text = String.Empty
        lblTotal.Text = String.Empty

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'End the App
        Me.Close()
    End Sub
End Class
Attached Images
File Type: png Form.png (74.3 KB, 8 views)

Last edited by Flyguy; 01-02-2011 at 10:11 AM. Reason: Added [code] [/code] tags
Reply With Quote
  #2  
Old 01-02-2011, 08:39 AM
AtmaWeapon's Avatar
AtmaWeaponGroupbox control reference AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

There's nothing special about controls in a group box, you reference them via variables like any other control. If you're using the Windows Forms designer, the value you assign to the Name property is the name of the variable created for the control *unless* the GenerateMember property is set to False, which causes the designer to omit generation of the variable.

I think you need to explain "reference controls in a group box" more thoroughly because I don't understand what you're asking.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 01-02-2011, 09:43 AM
Cruzersoul Cruzersoul is offline
Newcomer
 
Join Date: Jan 2011
Posts: 2
Default Clarification!

Ok, when you look at the form that I designed you will see a Groupbox whose text property is set to Options and contains 6 checkboxes. You will also see a Groupbox whose text property is set to Discount and it has 2 visible labels and 2 nonvisible labels. Heres an example, lets say that the user selected 3 checkboxes in the Options Groupbox. I need those 3 selected checkboxes to be converted to a number and stored in the nonvisible label next to the Number of options label.
Reply With Quote
  #4  
Old 01-02-2011, 11:44 AM
AtmaWeapon's Avatar
AtmaWeaponGroupbox control reference AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You have to do that work yourself.

First, I'd recommend never using invisible controls to store values again. Controls generally store only string values, and it's both inefficient and error-prone to store numbers as strings. In addition, even invisible controls have a window handle and use GDI resources. It's not a big deal unless you have several thousand invisible controls, but it's wasteful and not the best way to do things. Use variables to store information you don't necessarily need displayed.

Now to answer the question. As I pointed out, there's nothing special about the checkboxes in the groupbox. I can think of some ways to exploit some properties to get something like that, but it'd be brittle. It looks like what you want to do is for each checkbox, add some value to a subtotal if the box is checked. I imagine if the "V6" checkbox is checked, you want to add decV6 to the subtotal. The most direct way to do this would be to use If statements. Here's an example that makes assumptions about the name of your checkbox and assumes you have a _subtotal variable declared at the class level:
Code:
If chkV6.Checked Then
    _subtotal += decV6
End If
You'd need an if statement for each relevant checkbox.

There are techniques that would be a bit less tedious, but they are more advanced and I won't discuss them unless you press me to.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Groupbox control reference
Groupbox control reference
Groupbox control reference Groupbox control reference
Groupbox control reference
Groupbox control reference
Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference Groupbox control reference
Groupbox control reference
Groupbox control reference
 
Groupbox control reference
Groupbox control reference
 
-->