Results 1 to 30 of 30

Thread: Programming a billing application

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Programming a billing application

    I posted this in the wrong forum before, hopefully someone deletes it.

    I need to have this program display rental rates in a listbox when a button is pressed, and then allow the user to select which item they want to rent and if it's for a full day or a half day. When you click the "bill" button it should automatically enter a $30 deposit as well as the item you rented, and how much it is based on a full or half day rental.

    For now, is it alright for me to just hard code the rental rates into the first listbox or must I have them be read from a text file? I don't like doing that much but I'm not sure if I can then have the bill reflect the choices that are picked without having it read them from a file. Is it still fairly easy to get the bill totaled up this way, by using if statements or maybe the case statements? I haven't written the function for determining the bill yet. Here is my sample code for the first listbox.

    Code:
      Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    
            With lstRates.Items
                .Add("Price of Equipment    " & "Half-day    " & "Full-Day")
                .Add("1. " & "Rug cleaner        " & "$16.00      " & "$24.00")
                .Add("2. " & "Lawn mower         " & "$12.00      " & "$18.00")
                .Add("3. " & "Paint sprayer      " & "$20.00      " & "$30.00")
    
            End With
        End Sub
    End Class
    And this is the way the program looks when it is run just so you can get a better idea what I'm talking about.


  2. #2
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    What happens is one customer want to rent both a lawn mower and a paint sprayer? And the customer wants the lawn mower for a full day and the paint sprayer for only a half day?

    Not trying to be a smart a_ _, just thinking that maybe you need to consider making some changes to your design so you can address situations such as I have mentioned.

    If a customer is never going to rent more than one item then your design may work, but it is possible a customer might want to rent more than one item.

    Also, having all your items in one listbox is going to make you billing code more difficult to write.

    Price of Equipment,Half-day, and Full-Day are all selectable items in your list box. How are you going to handle it if the user selects one of them?

    Your form design and layout looks very nice, but I am not sure it will work very well as an application in its current design.

    Just some of my observatioins.

    Good Luck

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Well it's to be assumed that they only can rent one thing at a time as it's just a simple billing program.

    I'm not sure how I'm going to handle it in one listbox, but that's how the assignment is supposed to be done I'm just not sure how to go about getting it to recognize which item I'm picking and for how long it's being rented, like if having it read from a file would be better or if it doesn't make a difference.

    Thanks though.

  4. #4
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    It's better to put your possibilities each in a checkbox so that the user can make any wanted combination and then when the calculation button is pressed just check which check boxes are checked and compute the final value.

    the user interface would be something like in the attachment.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Quote Originally Posted by talkro
    It's better to put your possibilities each in a checkbox so that the user can make any wanted combination and then when the calculation button is pressed just check which check boxes are checked and compute the final value.

    the user interface would be something like in the attachment.

    I suppose that is better than the example I have. Would it still be as easy to write a function that I could call to do the final bill?

  6. #6
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    This can maybe help you.It's working but is not the bes solution.
    Attached Files Attached Files

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Thanks. I use an older version of Visual Studio but I can still at least open the form to see the programming part. I was thinking of using cases to do the checks for which option the people selected, now I just still have to write the function to do the bill.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Well I just got clarification from the teacher and I should be trying to use the example from the book, so for now it's just going to be the simple one I had before that only lets you pick one item at a time.

    I have a function that puts the item you pick in the bill listbox, but I can't get it to put the total along with it. Maybe this would be better if it wasn't in a function, I don't know. Here is the code:

    Code:
       Dim subTotal As String
        Dim total As String
     
    
        Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    
            With lstRates.Items
                .Add("Price of Equipment    " & "Half-day    " & "Full-Day")
                .Add("1. " & "Rug cleaner        " & "$16.00      " & "$24.00")
                .Add("2. " & "Lawn mower         " & "$12.00      " & "$18.00")
                .Add("3. " & "Paint sprayer      " & "$20.00      " & "$30.00")
    
            End With
        End Sub
        Function getInfo() As String
    
            Dim equip As String = txtEquip.Text
            Dim duration As String = txtDuration.Text
    
    
            Select Case equip
                Case "1"
                    Return "Rug cleaner"
                    If duration = "H" Then subTotal = 16.0
                    If duration = "F" Then subTotal = 24.0
    
                Case "2"
                    Return "Lawn mower"
                    If duration = "H" Then subTotal = 12.0
                    If duration = "F" Then subTotal = 18.0
                Case "3"
                    Return "Paint Sprayer"
                    If duration = "H" Then subTotal = 20.0
                    If duration = "F" Then subTotal = 30.0
            End Select
    
    
        End Function
    
    
        Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
            With lstBill.Items
                .Add("Receipt from Eddie's Equipment Rental")
                .Add("")
                .Add(getInfo() & subTotal)
    
            End With
        End Sub
    End Class

  9. #9
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    whatever code written after a return statement is not executed.
    Try a messageBox in one of the if statement in your cases.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    You mean like a message box that will ask if it's for a full day or half day? I'm not sure what you mean.

  11. #11
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    not asking, it's just for debugging purpose

    vb Code:
    1. Case "1"
    2.                 Return "Rug cleaner"
    3.                 If duration = "H" Then subTotal = 16.0
    4.                 MessageBox("Does the code reach here")
    5.                 If duration = "F" Then subTotal = 24.0

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Oh I see.

    For now I just wrote another function that will get the total charge be it full or half day, like this:

    Code:
    Function getInfo() As String
    
            Dim equip As String = txtEquip.Text
    
            Select Case equip
                Case "1"
                    Return "Rug cleaner" 
                   
    
                Case "2"
                    Return "Lawn mower"
                   
                Case "3"
                    Return "Paint Sprayer"
                  
            End Select
    
    
        End Function
        Function getDuration() As String
            Dim equip As String = txtEquip.Text
            Dim duration As String = txtDuration.Text
    
            Select Case duration.ToUpper
                Case "F"
                    If equip = "1" Then Return "24.0"
                    If equip = "2" Then Return "18.0"
                    If equip = "3" Then Return "30.0"
    
                Case "H"
                    If equip = "1" Then Return "16.0".ToString
    
                    If equip = "2" Then Return "12.0"
                    If equip = "3" Then Return "20.0"
            End Select
    
        End Function
    I'm sure it's a crappy way to do it, but I got it working somewhat. Just need to format the output.

  13. #13
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    formatCurrency(Total, 2)

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    I tried that but it didn't seem to work. I also tried to .tostring("C)" but that didn't seem to work either. Here is the latest code.

    Code:
     Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    
            With lstRates.Items
                .Add("Price of Equipment    " & "Half-day    " & "Full-Day")
                .Add("1. " & "Rug cleaner        " & "$16.00      " & "$24.00")
                .Add("2. " & "Lawn mower         " & "$12.00      " & "$18.00")
                .Add("3. " & "Paint sprayer      " & "$20.00      " & "$30.00")
    
            End With
        End Sub
        Function getInfo() As String
    
            Dim equip As String = txtEquip.Text
    
            Select Case equip
                Case "1"
                    Return "Rug cleaner"
    
                Case "2"
                    Return "Lawn mower"
    
                Case "3"
                    Return "Paint Sprayer"
                  
            End Select
    
    
        End Function
        Function getDuration() As String
            Dim equip As String = txtEquip.Text
            Dim duration As String = txtDuration.Text
    
            Select Case duration.ToUpper
    
                Case "F"
                    If equip = "1" Then Return "24"
                    If equip = "2" Then Return "18"
                    If equip = "3" Then Return "30"
    
                Case "H"
                    If equip = "1" Then Return "16"
                    If equip = "2" Then Return "12"
                    If equip = "3" Then Return "20"
            End Select
            FormatCurrency(getDuration, 2)
        End Function
    
    
    
        Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
            With lstBill.Items
                .Add("Receipt from Eddie's Equipment Rental")
                .Add("")
                .Add(getInfo() & "     " & getDuration()).ToString("C")
                .Add("Deposit" & "        $30.00")
                .Add("Total          " & getDuration() + 30).ToString("C")
    
            End With
        End Sub

  15. #15
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    try this:

    vb Code:
    1. If equip = "1" Then Return getDuration = "16"
    2.  
    3. formatCurrency(getDuration, 2)

  16. #16
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    Duplicate in error.

  17. #17
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    Code:
    Public Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
            With lstBill.Items
                .Add("Receipt from Eddie's Equipment Rental")
                .Add("")
                .Add(getInfo() & subTotal & "         " & FormatCurrency(getDuration, 2))
            End With
    
        End Sub

  18. #18
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    vb Code:
    1. Public Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
    2.         With lstBill.Items
    3.             .Add("Receipt from Eddie's Equipment Rental")
    4.             .Add("")
    5.             .Add(getInfo() & subTotal & "         " & getDuration)
    6.         End With
    7.  
    8.     End Sub

  19. #19
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    Code:
    .Add(getInfo() & subTotal & "         " & getDuration
    Doesn't format it with the $ sign.
    Code:
    .Add(getInfo() & subTotal & "         " & FormatCurrency(getDuration, 2))
    That adds the format $.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Ok that worked for one, but not this one:

    Code:
     Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
            Dim deposit = 30
            With lstBill.Items
                .Add("Receipt from Eddie's Equipment Rental")
                .Add("")
                .Add(getInfo() & "     " & FormatCurrency(getDuration, 2))
                .Add("Deposit" & "        $30.00")
                .Add("Total          " & FormatCurrency(getDuration, 2) + deposit)
    
            End With
        End Sub

  21. #21
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    You have used & to join all the other information in your code.
    Why are you using
    + deposit)
    I don't know if that is your only problem, but I am sure it is probably one.

    Also, Deposit has never been declared as a variable, but has just been used as a text string.
    You don't have anywhere on your form that indicates a deposit is paid.

    Something else I was wondering, why don't you put the code for your listbox lstRates into the Form Load event and then they would show when the form loads and you would not need the display button?

    Good Luck
    Last edited by AIS4U; Mar 19th, 2007 at 06:50 PM.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Quote Originally Posted by AIS4U
    You have used & to join all the other information in your code.
    Why are you using
    I don't know if that is your only problem, but I am sure it is probably one.

    Also, Deposit has never been declared as a variable, but has just been used as a text string.
    You don't have anywhere on your form that indicates a deposit is paid.

    Something else I was wondering, why don't you put the code for your listbox lstRates into the Form Load event and then they would show when the form loads and you would not need the display button?

    Good Luck

    Bah, missed the whole + thing That's probably it, I'll switch it and try again.

    The list box in the form load is a good idea, I just looked at the example and used exactly what was in the book.

    As far as the deposit thing, I wasn't sure how to handle that, I just know that there has to be a $30 deposit with every rental. I just stuck it in there.

    EDIT: Actually, looking at the + sign again, I did that just so the program would take the subtotal and add the $30 deposit to it.
    Last edited by meef; Mar 19th, 2007 at 07:47 PM.

  23. #23
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    I did that just so the program would take the subtotal and add the $30 deposit to it.
    Yes, but if you take subtotal our of the code, it still works. Again, you declared the variable for subtotal, but no value was ever assigned to it, so nothing can be added to it.

  24. #24
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    I am not being critical of your code, but you have used some rather bad coding practices. That's ok, as you learn more, you will improve.

    I put a textbox on the form to put the Deposit amount in. I have it set so that you can add any amount you want to it, but you could just a easily set the txtDep to $30.00 and leave it at that, if it is to be the same for all items.

    I moved the code to populate your first listobx to the form load event, but you of course can have it where ever you wish.

    I also added a blank line with a line going across to kind of make it look a little better.
    I did the same for the billing list box.

    I have just modified your code (which like I said, could use some refinement), but I got it to work using most of your code.

    Good Luck
    Attached Files Attached Files

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Yeah I know this program was badly coded, for some reason it screwed me all up. The main things that mess me up are some of the most basic things, like setting certain types to string, decimal, double, and integer. For some reason it just confuses me.

    I don't know, there's a few things that confuse me, but this is the first time I've ever used this language and I have to teach myself because it's an independent study, so hopefully I'll get there some time.

    Thanks for your help.

  26. #26
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Programming a billing application

    so hopefully I'll get there some time
    Hang in there. Don't get discouraged. I think you actually did quite well for just learning. And, most everyone who programs or tries to program, in any language, learns something new everyday.

    I haven't been using VB.Net very long (I usually use VB 6.0) so I am still learning. If I was better at it and knew more I could probably have given you some better advice or suggestions.

    Just keep on trying to write code and reading books about it and of course checking out VBForums, and I am sure you will be up to speed in no time.

    Best of Luck with your Programming

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Thanks. Your code works too. I added a textbox for the Deposit and set it to 30, converted it to currency, and hid it on the form, though I may just set it to 30 and make it read only.

    If I wanted errors to come up when someone didn't type in either an H, F, or 1, 2, or 3, could I just do another sort of if statement that would check, and have it output a msgbox telling the user they didn't input correct data, and have it not run the actual program part?

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    Ok, I tried doing it this way like I did for another program, but it says it can't cast "" to type boolean or something.

    Code:
    Public Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
            lstBill.Items.Clear()
    
            Dim equip As String = txtEquip.Text
            Dim duration As String = txtDuration.Text
    
            If equip And duration > 0 Then
    
    
    
            With lstBill.Items
                .Add("Receipt from Eddie's Equipment Rental")
                    .Add("")
                .Add(getInfo().PadRight(15) & FormatCurrency(getDuration, 2))
                .Add("Deposit".PadRight(15) & FormatCurrency(txtDep.Text, 2))
                    .Add("")
                .Add("Total".PadRight(15) & FormatCurrency(CInt(txtDep.Text) + FormatCurrency(getDuration, 2)))
                End With
            Else
                MessageBox.Show("You must enter the correct data", "Error", MessageBoxButtons.OK)
            End If
    
    
    
        End Sub
    Anyone know how I can get an error to occur if someone enters anything but what they're supposed to? In the cases that put the data into the list, I put an "else case" that will return a value of 0.
    Last edited by meef; Mar 20th, 2007 at 07:42 PM.

  29. #29
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Programming a billing application

    the condition of an IF statement must be a boolean

    If equip And duration > 0 Then
    won't work. you are comparing string and boolean expression (duration > 0)

    try:
    vb Code:
    1. dim equipNr, time as integer
    2. IF Not (Integer.TryParse(equip, equipNr)) Then equipNr = 0
    3. IF Not (Integer.TryParse(duration, time)) Then time = 0
    4. IF equipNr > 0 AndAlso time > 0 then .....

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Re: Programming a billing application

    I'm not sure what equipNr and time is representing, but for some reason when I put that in I get the same error. I took my old if statement out and it still marks that same line as if it were still there. It seems what you wrote is like what I wrote only different, i had the cases return a value of 0.

    Here's the rest of the code.

    Code:
       Function getInfo() As String
            Dim equip As String = txtEquip.Text
            Select Case equip
                Case "1"
                    Return "Rug cleaner"
    
                Case "2"
                    Return "Lawn mower"
                Case "3"
                    Return "Paint Sprayer"
                    'Case Else
                    '    Return 0
            End Select
        End Function
        Function getDuration() As String
            Dim equip As String = txtEquip.Text
            Dim duration As String = txtDuration.Text
            Select Case duration.ToUpper
                Case "F"
                    If equip = "1" Then Return "24"
                    If equip = "2" Then Return "18"
                    If equip = "3" Then Return "30"
                Case "H"
                    If equip = "1" Then Return "16"
                    If equip = "2" Then Return "12"
                    If equip = "3" Then Return "20"
                    'Case Else
                    '    Return 0
            End Select
            FormatCurrency(getDuration, 2)
        End Function
        Public Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
    
    
            Dim equip As String = txtEquip.Text
            Dim duration As String = txtDuration.Text
    
                With lstBill.Items
                    .Add("Receipt from Eddie's Equipment Rental")
                    .Add("")
                    .Add(getInfo().PadRight(15) & FormatCurrency(getDuration, 2))
                    .Add("Deposit".PadRight(15) & FormatCurrency(txtDep.Text, 2))
                    .Add("")
                    .Add("Total".PadRight(15) & FormatCurrency(CInt(txtDep.Text) + FormatCurrency(getDuration, 2)))
                End With
           
        End Sub
    EDIT 2: Wow, I actually got it working with something I tried by myself, impressive

    Code:
       Public Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
            lstBill.Items.Clear()
    
            Dim equip As String = Me.getInfo
            Dim duration As String = Me.getDuration
    
            If duration = 0 Then
                MessageBox.Show("You must input the correct information", "Error", MessageBoxButtons.OK)
            Else
    
                With lstBill.Items
                    .Add("Receipt from Eddie's Equipment Rental")
                    .Add("")
                    .Add(getInfo().PadRight(15) & FormatCurrency(getDuration, 2))
                    .Add("Deposit".PadRight(15) & FormatCurrency(txtDep.Text, 2))
                    .Add("")
                    .Add("Total".PadRight(15) & FormatCurrency(CInt(txtDep.Text) + FormatCurrency(getDuration, 2)))
                End With
            End If
        End Sub
    Last edited by meef; Mar 20th, 2007 at 09:13 PM.

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