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. -
Option Strict On
-
Option Explicit On
-
-
Public Class MobilePhoneCost
-
-
-
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
-
-
Dim objCustomer As Customer
-
Dim objInternetBuyer 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.TextLength < 1 Or _
-
Me.txtAddress.Text < "A" Then
-
MessageBox.Show("Enter your address in the box.", "Error")
-
Me.txtAddress.Clear()
-
Me.txtAddress.Focus()
-
InputError = True
-
-
'Is zip entered properly?
-
ElseIf Me.txtZipCode.MaskFull = False Then
-
MessageBox.Show("Enter your Zip code", "Error")
-
Me.txtZipCode.Clear()
-
Me.txtZipCode.Focus()
-
InputError = True
-
-
'Has a phone been selected?
-
ElseIf Me.cboPhoneChoice.SelectedIndex < 0 Then
-
MessageBox.Show("Please select a phone.", "Error")
-
Me.cboPhoneChoice.Focus()
-
InputError = True
-
-
'Has a charger been selected?
-
ElseIf Me.cboChargerStyle.SelectedIndex < 0 Then
-
MessageBox.Show("Please select a charger.", "Error")
-
Me.cboChargerStyle.Focus()
-
InputError = True
-
-
End If
-
-
'If no error process the phone purchase cost
-
If Not InputError Then
-
If Me.radInStore.Checked Then
-
objCustomer = New Customer(txtLastName.Text, txtAddress.Text, _
-
Convert.ToInt32(txtZipCode.Text), Convert.ToString(cboPhoneChoice.SelectedItem), _
-
Convert.ToString(cboChargerStyle.SelectedItem))
-
Me.lblTotalCost.Visible = True
-
Me.lblTotalCost.Text = "Total phone purchase cost: " _
-
& (objCustomer.ComputeCosts()).ToString("C2")
-
Else
-
objInternetBuyer = New InternetBuyer(txtLastName.Text, txtAddress.Text, _
-
CInt(txtZipCode.Text), txtEmail.Text, CStr(cboPhoneChoice.SelectedItem))
-
Me.lblTotalCost.Visible = True
-
Me.lblTotalCost.Text = "Total Phone purchase cost: " _
-
& (objInternetBuyer.ComputeCosts()).ToString("C2")
-
-
End If
-
End If
-
End Sub
-
-
-
Private Sub radInStore_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radInStore.CheckedChanged
-
'This event handler is executed when the In store radio button
-
'is selected. It hides the buyer type radio buttons.
-
-
Me.grpBuyer.Visible = True
-
-
End Sub
-
-
-
Private Sub radInternet_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radInternet.CheckedChanged
-
'This event handler is executed when the Internet radio button
-
'is selected. It makes the buyer type radio buttons visible.
-
-
Me.grpBuyer.Visible = True
-
Me.lblEmail.Visible = True
-
Me.txtEmail.Visible = True
-
-
If Me.txtEmail.TextLength < 1 Or _
-
Me.txtEmail.Text < "A" Then
-
MessageBox.Show("Enter your E-mail address in the box.", "Error")
-
Me.txtEmail.Clear()
-
Me.txtEmail.Focus()
-
End If
-
-
End Sub
-
-
-
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 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.Clear()
-
Me.txtZipCode.Clear()
-
Me.txtEmail.Clear()
-
Me.cboChargerStyle.SelectedIndex = -1
-
Me.cboPhoneChoice.SelectedIndex = -1
-
Me.radInStore.Checked = True
-
Me.radInternet.Checked = True
-
Me.grpBuyer.Visible = True
-
Me.lblTotalCost.Visible = False
-
Me.txtLastName.Focus()
-
End Sub
-
-
End Class
-
And here is the other class. -
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 objPhoneCostFile 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.cboPhoneChoice.SelectedIndex = 0 Then
-
decAmount = 279.81D
-
ElseIf Me.cboPhoneChoice.SelectedIndex = 1 Then
-
decAmount = 193.71D
-
ElseIf Me.cboPhoneChoice.SelectedIndex = 2 Then
-
decAmount = 328.44D
-
ElseIf Me.cboPhoneChoice.SelectedIndex = 3 Then
-
decAmount = 253.72D
-
ElseIf Me.cboPhoneChoice.SelectedIndex = 4 Then
-
decAmount = 479.36D
-
End If
-
-
Dim decAmount1 As Decimal
-
If Me.cboChargerStyle.SelectedIndex = 0 Then
-
decAmount1 = 63.92D
-
ElseIf Me.cboChargerStyle.SelectedIndex = 1 Then
-
decAmount1 = 42.66D
-
ElseIf Me.cboChargerStyle.SelectedIndex = 2 Then
-
decAmount1 = 27.31D
-
End If
-
-
_decCost = decAmount + decAmount1 + _decSalesTax
-
Return _decCost
-
End Function
-
-
End Class
-
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?
3 1458
Question moved to .net forum.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Graham Banks |
last post by:
Does using multiple inheritance introduce any more performance overhead than
single inheritance?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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).
--...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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,...
| |