Multiple classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tragic54
    New Member
    • Feb 2008
    • 20

    Multiple classes

    Alright so im having a problem getting a value from a couple combo boxes based on their index. Im calling the objects from the main form to calculatecost() from 2 other classes. Anyways heres the main form code and i'll post one class after that with the combo box selected values.

    [code=vbnet]
    Option Strict On
    Option Explicit On

    Public Class MobilePhoneCost


    Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCalculate.Cl ick

    Dim objCustomer As Customer
    Dim objInternetBuye r As InternetBuyer
    Dim InputError As Boolean = False


    'Is Last Name entered properly?
    If Me.txtLastName. TextLength < 1 Or _
    Me.txtLastName. Text < "A" Then
    MessageBox.Show ("Enter your Last name in the Box.", "Error")
    Me.txtLastName. Clear()
    Me.txtLastName. Focus()
    InputError = True

    'Is the Address entered properly?
    ElseIf Me.txtAddress.T extLength < 1 Or _
    Me.txtAddress.T ext < "A" Then
    MessageBox.Show ("Enter your address in the box.", "Error")
    Me.txtAddress.C lear()
    Me.txtAddress.F ocus()
    InputError = True

    'Is zip entered properly?
    ElseIf Me.txtZipCode.M askFull = False Then
    MessageBox.Show ("Enter your Zip code", "Error")
    Me.txtZipCode.C lear()
    Me.txtZipCode.F ocus()
    InputError = True

    'Has a phone been selected?
    ElseIf Me.cboPhoneChoi ce.SelectedInde x < 0 Then
    MessageBox.Show ("Please select a phone.", "Error")
    Me.cboPhoneChoi ce.Focus()
    InputError = True

    'Has a charger been selected?
    ElseIf Me.cboChargerSt yle.SelectedInd ex < 0 Then
    MessageBox.Show ("Please select a charger.", "Error")
    Me.cboChargerSt yle.Focus()
    InputError = True

    End If

    'If no error process the phone purchase cost
    If Not InputError Then
    If Me.radInStore.C hecked Then
    objCustomer = New Customer(txtLas tName.Text, txtAddress.Text , _
    Convert.ToInt32 (txtZipCode.Tex t), Convert.ToStrin g(cboPhoneChoic e.SelectedItem) , _
    Convert.ToStrin g(cboChargerSty le.SelectedItem ))
    Me.lblTotalCost .Visible = True
    Me.lblTotalCost .Text = "Total phone purchase cost: " _
    & (objCustomer.Com puteCosts()).ToString("C2")
    Else
    objInternetBuye r = New InternetBuyer(t xtLastName.Text , txtAddress.Text , _
    CInt(txtZipCode .Text), txtEmail.Text, CStr(cboPhoneCh oice.SelectedIt em))
    Me.lblTotalCost .Visible = True
    Me.lblTotalCost .Text = "Total Phone purchase cost: " _
    & (objInternetBuy er.ComputeCosts ()).ToString("C 2")

    End If
    End If
    End Sub


    Private Sub radInStore_Chec kedChanged(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles radInStore.Chec kedChanged
    'This event handler is executed when the In store radio button
    'is selected. It hides the buyer type radio buttons.

    Me.grpBuyer.Vis ible = True

    End Sub


    Private Sub radInternet_Che ckedChanged(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles radInternet.Che ckedChanged
    'This event handler is executed when the Internet radio button
    'is selected. It makes the buyer type radio buttons visible.

    Me.grpBuyer.Vis ible = True
    Me.lblEmail.Vis ible = True
    Me.txtEmail.Vis ible = True

    If Me.txtEmail.Tex tLength < 1 Or _
    Me.txtEmail.Tex t < "A" Then
    MessageBox.Show ("Enter your E-mail address in the box.", "Error")
    Me.txtEmail.Cle ar()
    Me.txtEmail.Foc us()
    End If

    End Sub


    Private Sub btnClear_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnClear.Click
    'This event handler is executed when the user clicks the Clear Form
    'button. It resets all objects on the user interface.

    Me.txtLastName. Clear()
    Me.txtAddress.C lear()
    Me.txtZipCode.C lear()
    Me.txtEmail.Cle ar()
    Me.cboChargerSt yle.SelectedInd ex = -1
    Me.cboPhoneChoi ce.SelectedInde x = -1
    Me.radInStore.C hecked = True
    Me.radInternet. Checked = True
    Me.grpBuyer.Vis ible = True
    Me.lblTotalCost .Visible = False
    Me.txtLastName. Focus()
    End Sub

    End Class
    [/code]

    And here is the other class.

    [code=vbnet]
    Option Strict On
    Option Explicit On

    Public Class Customer
    Inherits MobilePhoneCost

    Protected _strLastName As String
    Protected _strAddress As String
    Protected _intZipCode As Integer
    Protected _strPhoneChoice As String
    Protected _strCharger As String
    Protected _decCost As Decimal
    Protected _decSalesTax As Decimal = 0.0775D

    Dim objPhoneCostFil e As PhoneCostFile

    Sub New(ByVal strLastName As String, ByVal strAddress As String, ByVal intZipCode As Integer, _
    ByVal strPhoneChoice As String, ByVal strCharger As String)

    _strLastName = strLastName
    _strAddress = strAddress
    _intZipCode = intZipCode
    _strPhoneChoice = strPhoneChoice
    _strCharger = strCharger

    End Sub


    Overridable Function ComputeCosts() As Decimal

    Dim decAmount As Decimal

    If Me.cboPhoneChoi ce.SelectedInde x = 0 Then
    decAmount = 279.81D
    ElseIf Me.cboPhoneChoi ce.SelectedInde x = 1 Then
    decAmount = 193.71D
    ElseIf Me.cboPhoneChoi ce.SelectedInde x = 2 Then
    decAmount = 328.44D
    ElseIf Me.cboPhoneChoi ce.SelectedInde x = 3 Then
    decAmount = 253.72D
    ElseIf Me.cboPhoneChoi ce.SelectedInde x = 4 Then
    decAmount = 479.36D
    End If

    Dim decAmount1 As Decimal
    If Me.cboChargerSt yle.SelectedInd ex = 0 Then
    decAmount1 = 63.92D
    ElseIf Me.cboChargerSt yle.SelectedInd ex = 1 Then
    decAmount1 = 42.66D
    ElseIf Me.cboChargerSt yle.SelectedInd ex = 2 Then
    decAmount1 = 27.31D
    End If

    _decCost = decAmount + decAmount1 + _decSalesTax
    Return _decCost
    End Function

    End Class
    [/code]

    I know theres something wrong with the combo selected index, but i don't know exactly how to fix it in order for _decCost to return the value to the main class. When this is executed, it calculates the _decSalesTax just fine, but ignores all the combobox items? Anyone point me in the right direction?
    Last edited by debasisdas; Apr 21 '08, 05:18 AM. Reason: added code=vbnet tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to .net forum.

    Comment

    • balame2004
      New Member
      • Mar 2008
      • 142

      #3
      Originally posted by debasisdas
      Question moved to .net forum.
      Please debug and check(in immediate window) selected index value of combobox. I think it might be -1 when else-if statement is being executed .


      -Balaji U

      Comment

      • tragic54
        New Member
        • Feb 2008
        • 20

        #4
        I don't understand what you mean. All comboboxes begin their index at 0. When executed, and trying to go through the selectedindex if statements to find which 'phone' was selected, it returns a value of 0.

        Comment

        Working...