473,396 Members | 1,892 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,396 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. Option Strict On
  2. Option Explicit On
  3.  
  4. Public Class MobilePhoneCost
  5.  
  6.  
  7.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
  8.  
  9.         Dim objCustomer As Customer
  10.         Dim objInternetBuyer As InternetBuyer
  11.         Dim InputError As Boolean = False
  12.  
  13.  
  14.         'Is Last Name entered properly?
  15.         If Me.txtLastName.TextLength < 1 Or _
  16.         Me.txtLastName.Text < "A" Then
  17.             MessageBox.Show("Enter your Last name in the Box.", "Error")
  18.             Me.txtLastName.Clear()
  19.             Me.txtLastName.Focus()
  20.             InputError = True
  21.  
  22.             'Is the Address entered properly?
  23.         ElseIf Me.txtAddress.TextLength < 1 Or _
  24.         Me.txtAddress.Text < "A" Then
  25.             MessageBox.Show("Enter your address in the box.", "Error")
  26.             Me.txtAddress.Clear()
  27.             Me.txtAddress.Focus()
  28.             InputError = True
  29.  
  30.             'Is zip entered properly?
  31.         ElseIf Me.txtZipCode.MaskFull = False Then
  32.             MessageBox.Show("Enter your Zip code", "Error")
  33.             Me.txtZipCode.Clear()
  34.             Me.txtZipCode.Focus()
  35.             InputError = True
  36.  
  37.             'Has a phone been selected?
  38.         ElseIf Me.cboPhoneChoice.SelectedIndex < 0 Then
  39.             MessageBox.Show("Please select a phone.", "Error")
  40.             Me.cboPhoneChoice.Focus()
  41.             InputError = True
  42.  
  43.             'Has a charger been selected?
  44.         ElseIf Me.cboChargerStyle.SelectedIndex < 0 Then
  45.             MessageBox.Show("Please select a charger.", "Error")
  46.             Me.cboChargerStyle.Focus()
  47.             InputError = True
  48.  
  49.         End If
  50.  
  51.         'If no error process the phone purchase cost
  52.         If Not InputError Then
  53.             If Me.radInStore.Checked Then
  54.                 objCustomer = New Customer(txtLastName.Text, txtAddress.Text, _
  55.                 Convert.ToInt32(txtZipCode.Text), Convert.ToString(cboPhoneChoice.SelectedItem), _
  56.                 Convert.ToString(cboChargerStyle.SelectedItem))
  57.                 Me.lblTotalCost.Visible = True
  58.                 Me.lblTotalCost.Text = "Total phone purchase cost: " _
  59.                 & (objCustomer.ComputeCosts()).ToString("C2")
  60.             Else
  61.                 objInternetBuyer = New InternetBuyer(txtLastName.Text, txtAddress.Text, _
  62.                 CInt(txtZipCode.Text), txtEmail.Text, CStr(cboPhoneChoice.SelectedItem))
  63.                 Me.lblTotalCost.Visible = True
  64.                 Me.lblTotalCost.Text = "Total Phone purchase cost: " _
  65.                 & (objInternetBuyer.ComputeCosts()).ToString("C2")
  66.  
  67.             End If
  68.         End If
  69.     End Sub
  70.  
  71.  
  72.     Private Sub radInStore_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radInStore.CheckedChanged
  73.         'This event handler is executed when the In store radio button
  74.         'is selected.  It hides the buyer type radio buttons.
  75.  
  76.         Me.grpBuyer.Visible = True
  77.  
  78.     End Sub
  79.  
  80.  
  81.     Private Sub radInternet_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radInternet.CheckedChanged
  82.         'This event handler is executed when the Internet radio button
  83.         'is selected.  It makes the buyer type radio buttons visible.
  84.  
  85.         Me.grpBuyer.Visible = True
  86.         Me.lblEmail.Visible = True
  87.         Me.txtEmail.Visible = True
  88.  
  89.         If Me.txtEmail.TextLength < 1 Or _
  90.         Me.txtEmail.Text < "A" Then
  91.             MessageBox.Show("Enter your E-mail address in the box.", "Error")
  92.             Me.txtEmail.Clear()
  93.             Me.txtEmail.Focus()
  94.         End If
  95.  
  96.     End Sub
  97.  
  98.  
  99.     Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
  100.         'This event handler is executed when the user clicks the Clear Form
  101.         'button.  It resets all objects on the user interface.
  102.  
  103.         Me.txtLastName.Clear()
  104.         Me.txtAddress.Clear()
  105.         Me.txtZipCode.Clear()
  106.         Me.txtEmail.Clear()
  107.         Me.cboChargerStyle.SelectedIndex = -1
  108.         Me.cboPhoneChoice.SelectedIndex = -1
  109.         Me.radInStore.Checked = True
  110.         Me.radInternet.Checked = True
  111.         Me.grpBuyer.Visible = True
  112.         Me.lblTotalCost.Visible = False
  113.         Me.txtLastName.Focus()
  114.     End Sub
  115.  
  116. End Class
  117.  
And here is the other class.

Expand|Select|Wrap|Line Numbers
  1. Option Strict On
  2. Option Explicit On
  3.  
  4. Public Class Customer
  5.     Inherits MobilePhoneCost
  6.  
  7.     Protected _strLastName As String
  8.     Protected _strAddress As String
  9.     Protected _intZipCode As Integer
  10.     Protected _strPhoneChoice As String
  11.     Protected _strCharger As String
  12.     Protected _decCost As Decimal
  13.     Protected _decSalesTax As Decimal = 0.0775D
  14.  
  15.     Dim objPhoneCostFile As PhoneCostFile
  16.  
  17.     Sub New(ByVal strLastName As String, ByVal strAddress As String, ByVal intZipCode As Integer, _
  18.     ByVal strPhoneChoice As String, ByVal strCharger As String)
  19.  
  20.         _strLastName = strLastName
  21.         _strAddress = strAddress
  22.         _intZipCode = intZipCode
  23.         _strPhoneChoice = strPhoneChoice
  24.         _strCharger = strCharger
  25.  
  26.     End Sub
  27.  
  28.  
  29.     Overridable Function ComputeCosts() As Decimal
  30.  
  31.         Dim decAmount As Decimal
  32.  
  33.         If Me.cboPhoneChoice.SelectedIndex = 0 Then
  34.             decAmount = 279.81D
  35.         ElseIf Me.cboPhoneChoice.SelectedIndex = 1 Then
  36.             decAmount = 193.71D
  37.         ElseIf Me.cboPhoneChoice.SelectedIndex = 2 Then
  38.             decAmount = 328.44D
  39.         ElseIf Me.cboPhoneChoice.SelectedIndex = 3 Then
  40.             decAmount = 253.72D
  41.         ElseIf Me.cboPhoneChoice.SelectedIndex = 4 Then
  42.             decAmount = 479.36D
  43.         End If
  44.  
  45.         Dim decAmount1 As Decimal
  46.         If Me.cboChargerStyle.SelectedIndex = 0 Then
  47.             decAmount1 = 63.92D
  48.         ElseIf Me.cboChargerStyle.SelectedIndex = 1 Then
  49.             decAmount1 = 42.66D
  50.         ElseIf Me.cboChargerStyle.SelectedIndex = 2 Then
  51.             decAmount1 = 27.31D
  52.         End If
  53.  
  54.         _decCost = decAmount + decAmount1 + _decSalesTax
  55.         Return _decCost
  56.     End Function
  57.  
  58. End Class
  59.  
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?
Apr 21 '08 #1
3 1458
debasisdas
8,127 Expert 4TB
Question moved to .net forum.
Apr 21 '08 #2
balame2004
142 100+
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
Apr 21 '08 #3
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.
Apr 21 '08 #4

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

Similar topics

2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
8
by: Gaetan | last post by:
hi i have 2 classes A1 and A2 implementing a problem with 2 different ways i also have 2 other classes X1 and X2 implementing an other problem i need classes that provide A1+X1 methods,...
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
15
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
2
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.