0

Yes this is for a homework assignment. I am getting closer to what I need but am running into a block. my code shows how far I have gotten. I am pretty sure I can handle the washer gallons and cost part. its the second section I am aving problems with. I have included the requirements below. I have done something similar in Java to do an amortization table for a mortgage calculator. I am just really unsure of how to get it to display what i need. Any advice in the right direction would be great.
The user should be able to do the following:

• Enter the cost per kilowatt-hour.
• Select from a list of home appliances which includes a washer, among other appliances.
• Enter the power needed in kilowatts (kW) for the selected appliance.
• Enter the number of hours used per day for the selected appliance.
• If the washer is selected, enter both the number of gallons of water used by the washer per hour and the cost per gallon.

The program should do the following:

• Validate that the data entered has the correct format, and is within a reasonable range.
• Calculate and display the cost for operating a home appliance as soon as the data is entered.
• Create a listing area to display each of the following for each appliance entered:

o Home appliance
o Number of hours per day
o Cost
o Display and update the total cost of all appliances, as soon as a new entry is added to the listing area.

Public Class Form1

    Dim Power As Double
    Dim Hours As Double
    Dim Price As Double
    Dim Estimated As Double


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

        txtCostPerHour.Text = "1"
        txtHours.Text = "1"
        txtPower.Text = "1"
        txtEstimated.Text = ""
        Power = CDbl(txtPower.Text)
        Hours = CDbl(txtHours.Text)
        Price = CDbl(txtCostPerHour.Text)
        'Estimated = ((Power * Hours) * Price) * 365
        'txtEstimated.Text = Estimated.ToString("C")
        cbxAppliances.SelectedIndex = -1
        cbxAppliances.Focus()

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

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

        Power = CDbl(txtPower.Text)
        Hours = CDbl(txtHours.Text)
        Price = CDbl(txtCostPerHour.Text)
        Estimated = ((Power * Hours) * Price) * 365
        txtEstimated.Text = Estimated.ToString("C")

    End Sub

    Private Sub txtPower_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPower.TextChanged

        If txtPower.TextLength = 0 Then
            MessageBox.Show("You must enter an amount here")
        End If

        If Not IsNumeric(txtPower.Text) Then
            MessageBox.Show("Please enter numeric values only")
        End If

    End Sub

    Private Sub txtHours_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHours.TextChanged

        If Not IsNumeric(txtHours.Text) Then
            MessageBox.Show("Please enter numeric values only")
            txtHours.Clear()
        End If

        If txtHours.TextLength = 0 Then
            MessageBox.Show("You must enter an amount here")
        End If

    End Sub

    Private Sub txtCostPerHour_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCostPerHour.TextChanged

        If txtCostPerHour.TextLength = 0 Then
            MessageBox.Show("You must enter an amount here")
        End If

        If Not IsNumeric(txtCostPerHour.Text) Then
            MessageBox.Show("Please enter numeric values only")
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Set ListView Properties
        ListView1.View = View.Details
        ListView1.GridLines = True
        ListView1.FullRowSelect = True
        ListView1.HideSelection = False
        ListView1.MultiSelect = False

        ' Create Columns Headers
        ListView1.Columns.Add("Item Number")
        ListView1.Columns.Add("Appliance")
        ListView1.Columns.Add("Hours Used Per Day")
        ListView1.Columns.Add("Annual Cost for Each Item")
        ListView1.Columns.Add("Total Annual Cost for All Items")

        Dim tempValue As Integer = 0

        For i As Integer = 1 To 9

            ' Create List View Item (Row)
            Dim lvi As New ListViewItem

            ' First Column can be the listview item's Text
            lvi.Text = i.ToString

            ' Second Column is the first sub item
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)

            ' Third Column is the second sub item
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)
            ' Fourth Column is the second sub item
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)
            ' Fifth Column is the second sub item
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)

            ' Add the ListViewItem to the ListView
            ListView1.Items.Add(lvi)

        Next

    End Sub

End Class

Edited by Reverend Jim: Fixed formatting

1
Contributor
1
Reply
13
Views
4 Years
Discussion Span
Last Post by jab8288
0
Public Class Form1
    Dim Power As Double
    Dim Hours As Double
    Dim Price As Double
    Dim Estimated As Double


    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtCostPerHour.Text = "1"
        txtHours.Text = "1"
        txtPower.Text = "1"
        txtEstimated.Text = ""
        Power = CDbl(txtPower.Text)
        Hours = CDbl(txtHours.Text)
        Price = CDbl(txtCostPerHour.Text)
        'Estimated = ((Power * Hours) * Price) * 365
        'txtEstimated.Text = Estimated.ToString("C")
        cbxAppliances.SelectedIndex = -1
        cbxAppliances.Focus()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Power = CDbl(txtPower.Text)
        Hours = CDbl(txtHours.Text)
        Price = CDbl(txtCostPerHour.Text)
        Estimated = ((Power * Hours) * Price) * 365
        txtEstimated.Text = Estimated.ToString("C")


    End Sub

    Private Sub txtPower_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPower.TextChanged
        If txtPower.TextLength = 0 Then
            MessageBox.Show("You must enter an amount here")
        End If
        If Not IsNumeric(txtPower.Text) Then
            MessageBox.Show("Please enter numeric values only")
        End If
    End Sub

    Private Sub txtHours_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHours.TextChanged
        If Not IsNumeric(txtHours.Text) Then
            MessageBox.Show("Please enter numeric values only")
            txtHours.Clear()
        End If
        If txtHours.TextLength = 0 Then
            MessageBox.Show("You must enter an amount here")
        End If


    End Sub

    Private Sub txtCostPerHour_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCostPerHour.TextChanged
        If txtCostPerHour.TextLength = 0 Then
            MessageBox.Show("You must enter an amount here")
        End If
        If Not IsNumeric(txtCostPerHour.Text) Then
            MessageBox.Show("Please enter numeric values only")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Set ListView Properties  
        ListView1.View = View.Details
        ListView1.GridLines = True
        ListView1.FullRowSelect = True
        ListView1.HideSelection = False
        ListView1.MultiSelect = False

        ' Create Columns Headers  
        ListView1.Columns.Add("Item Number")
        ListView1.Columns.Add("Appliance")
        ListView1.Columns.Add("Hours Used Per Day")
        ListView1.Columns.Add("Annual Cost for Each Item")
        ListView1.Columns.Add("Total Annual Cost for All Items")

        Dim tempValue As Integer = 0

        For i As Integer = 1 To 9

            ' Create List View Item (Row)  
            Dim lvi As New ListViewItem

            ' First Column can be the listview item's Text  
            lvi.Text = i.ToString

            ' Second Column is the first sub item  
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)

            ' Third Column is the second sub item  
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)
            ' Fourth Column is the second sub item 
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)
            ' Fifth Column is the second sub item 
            tempValue = tempValue + 1
            lvi.SubItems.Add(tempValue.ToString)

            ' Add the ListViewItem to the ListView  
            ListView1.Items.Add(lvi)

        Next
    End Sub
End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.