Output in List Boxes - Help Please
Here is my code, I cannot produce the output in the lstresults.Text box
Code:
Public Class Expense_Report
Const expenseDivide As Double = 50
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Sub getResults()
Dim fmtStr As String = "{0, -26} {1, -10:C2}"
Dim entertainment As Double = CType(txtEntertainment.Text, Double)
Dim airline As Double = CType(txtPlaneFare.Text, Double)
Dim lodging As Double = CType(txtLodging.Text, Double)
Dim taxi As Double = CType(txtTaxi.Text, Double)
Dim sum As Double = 0
Dim fun As Double = 0
Dim total As Double = 0
With lstResults.Items
sum = CType(txtPlaneFare.Text, Double) + CType(txtLodging.Text, Double) + CType(txtTaxi.Text, Double)
fun = (entertainment * (expenseDivide / 100))
total = sum + fun
lstResults.Items.Clear()
lstResults.Items.Add("Business Travel Expense")
lstResults.Items.Add("")
lstResults.Items.Add("Organization visited : ")
lstResults.Items.Add(txtOrganization.Text)
lstResults.Items.Add(txtDates.Text & " in " & txtLocation.Text)
lstResults.Items.Add("")
lstResults.Items.Add(String.Format(fmtStr, "Meals and entertainment", entertainment))
lstResults.Items.Add(String.Format(fmtStr, "Airplane fare", airline))
lstResults.Items.Add(String.Format(fmtStr, "Lodging", lodging))
lstResults.Items.Add(String.Format(fmtStr, "Taxi fares", taxi))
lstResults.Items.Add("")
lstResults.Items.Add(String.Format(fmtStr, "Total other than meals and entertainment:", sum))
lstResults.Items.Add(String.Format(fmtStr, "50% of meals and entertainment:", fun))
End With
End Sub
End Class
Re: Output in List Boxes - Help Please
I am confused with your code. It looks like you are creating a Windows forms project? If so when the form is created for you, it creates a class already called "Form1". Knowing that you can put your getResults sub within it as a method. Therefore I don't think you need the class Expense_Report. I think this is the reason why you can't write anything to the lstResults listbox, since it does not exist in the Expense_Report class and is out of scope. So I would have done the following:
vb Code:
Public Class Form1
Const expenseDivide As Double = 50
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Sub getResults()
Dim fmtStr As String = "{0, -26} {1, -10:C2}"
Dim entertainment As Double = CType(txtEntertainment.Text, Double)
Dim airline As Double = CType(txtPlaneFare.Text, Double)
Dim lodging As Double = CType(txtLodging.Text, Double)
Dim taxi As Double = CType(txtTaxi.Text, Double)
Dim sum As Double = 0
Dim fun As Double = 0
Dim total As Double = 0
With lstResults.Items
sum = CType(txtPlaneFare.Text, Double) + CType(txtLodging.Text, Double) + CType(txtTaxi.Text, Double)
fun = (entertainment * (expenseDivide / 100))
total = sum + fun
lstResults.Items.Clear()
lstResults.Items.Add("Business Travel Expense")
lstResults.Items.Add("")
lstResults.Items.Add("Organization visited : ")
lstResults.Items.Add(txtOrganization.Text)
lstResults.Items.Add(txtDates.Text & " in " & txtLocation.Text)
lstResults.Items.Add("")
lstResults.Items.Add(String.Format(fmtStr, "Meals and entertainment", entertainment))
lstResults.Items.Add(String.Format(fmtStr, "Airplane fare", airline))
lstResults.Items.Add(String.Format(fmtStr, "Lodging", lodging))
lstResults.Items.Add(String.Format(fmtStr, "Taxi fares", taxi))
lstResults.Items.Add("")
lstResults.Items.Add(String.Format(fmtStr, "Total other than meals and entertainment:", sum))
lstResults.Items.Add(String.Format(fmtStr, "50% of meals and entertainment:", fun))
End With
End Sub
End Class