Results 1 to 2 of 2

Thread: Output in List Boxes - Help Please

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    8

    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

  2. #2
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    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:
    1. Public Class Form1
    2.     Const expenseDivide As Double = 50
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.  
    5.     End Sub
    6.     Sub getResults()
    7.         Dim fmtStr As String = "{0, -26}  {1, -10:C2}"
    8.         Dim entertainment As Double = CType(txtEntertainment.Text, Double)
    9.         Dim airline As Double = CType(txtPlaneFare.Text, Double)
    10.         Dim lodging As Double = CType(txtLodging.Text, Double)
    11.         Dim taxi As Double = CType(txtTaxi.Text, Double)
    12.  
    13.         Dim sum As Double = 0
    14.         Dim fun As Double = 0
    15.         Dim total As Double = 0
    16.  
    17.         With lstResults.Items
    18.             sum = CType(txtPlaneFare.Text, Double) + CType(txtLodging.Text, Double) + CType(txtTaxi.Text, Double)
    19.             fun = (entertainment * (expenseDivide / 100))
    20.             total = sum + fun
    21.  
    22.  
    23.             lstResults.Items.Clear()
    24.             lstResults.Items.Add("Business Travel Expense")
    25.             lstResults.Items.Add("")
    26.             lstResults.Items.Add("Organization visited : ")
    27.             lstResults.Items.Add(txtOrganization.Text)
    28.             lstResults.Items.Add(txtDates.Text & " in " & txtLocation.Text)
    29.             lstResults.Items.Add("")
    30.             lstResults.Items.Add(String.Format(fmtStr, "Meals and entertainment", entertainment))
    31.             lstResults.Items.Add(String.Format(fmtStr, "Airplane fare", airline))
    32.             lstResults.Items.Add(String.Format(fmtStr, "Lodging", lodging))
    33.             lstResults.Items.Add(String.Format(fmtStr, "Taxi fares", taxi))
    34.             lstResults.Items.Add("")
    35.             lstResults.Items.Add(String.Format(fmtStr, "Total other than meals and entertainment:", sum))
    36.             lstResults.Items.Add(String.Format(fmtStr, "50% of meals and entertainment:", fun))
    37.         End With
    38.     End Sub
    39. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width