Private Sub btnBill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBill.Click

        item = txtItem.Text
        duration = txtduration.Text

        Dim fmtstr As String = "{0, -15} {1, 17:c2}"
        '-----------------------------------------------------------------------------------------------
        lstResult2.Items.Add(" Receipt from Eddie's Equipment Rental")
        Select Case item.ToUpper & duration.ToUpper

            Case "1", "h"
                lstResult2.Items.Add(String.Format(fmtstr, "Rug cleaner", 16))
            Case "2", "h"
                lstResult2.Items.Add(String.Format(fmtstr, "Lawn mower", 12))
            Case "3", "h"
                lstResult2.Items.Add(String.Format(fmtstr, "Paint sprayer", 20))
            Case "1", "f"
                lstResult2.Items.Add(String.Format(fmtstr, "Rug cleaner", 24))
            Case "2", "f"
                lstResult2.Items.Add(String.Format(fmtstr, "Lawn mower", 18))
            Case "3", "f"
                lstResult2.Items.Add(String.Format(fmtstr, "Paint sprayer", 40))
        End Select
        lstResult2.Items.Add(String.Format(fmtstr, "Deposit", 30))
        lstResult2.Items.Add(String.Format(fmtstr, "Total", 25 + 25))
        '-----------------------------------------------------------------------    End Sub
End Class

Dani AI

Generated

The symptom in this thread was a mismatch between the Select Case expression and the Case labels. correctly recommended validating the evaluated expression with a breakpoint; pointed out that concatenating the two inputs produces a different string than each separate value, so the Case labels need to match that combined value. confirmed a fix. Below are cleaner, more robust ways to structure the matching so the ListBox shows the expected output.

Use a nested Select Case so each input is compared separately (keeps logic clear and easy to maintain):

Dim it = txtItem.Text.Trim().ToUpperInvariant()
Dim dur = txtDuration.Text.Trim().ToUpperInvariant()

Select Case it
    Case "1"
        Select Case dur
            Case "H"
                price = 16D
            Case "F"
                price = 24D
        End Select
    Case "2"
        ' ...
End Select

Or use a condition-driven Select Case (useful when combinations are scattered):

Select Case True
    Case it = "1" AndAlso dur = "H"
        price = 16D
    Case it = "1" AndAlso dur = "F"
        price = 24D
    Case Else
        ' handle invalid input
End Select

For cleaner mapping and easier updates, use a dictionary keyed by a normalized pair:

Dim prices As New Dictionary(Of String, Decimal) From {
    {"1|H", 16D}, {"1|F", 24D}
}
Dim key = it & "|" & dur
If prices.TryGetValue(key, price) Then
    ' add to listbox
End If

Extra tips: always normalize input with Trim() and ToUpperInvariant() or use String.Equals(..., StringComparison.OrdinalIgnoreCase). Use breakpoints and the Immediate window to inspect it, dur, and the final expression. Enable Option Strict On to catch implicit-conversion mistakes early. If you keep the single concatenated expression approach, ensure the Case labels match the exact concatenated string (e.g., "1H"), as noted.

Recommended Answers

All 3 Replies

Private Sub btnBill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBill.Click

        item = txtItem.Text
        duration = txtduration.Text

        Dim fmtstr As String = "{0, -15} {1, 17:c2}"
        '-----------------------------------------------------------------------------------------------
        lstResult2.Items.Add(" Receipt from Eddie's Equipment Rental")
        Select Case item.ToUpper & duration.ToUpper

            Case "1", "h"
                lstResult2.Items.Add(String.Format(fmtstr, "Rug cleaner", 16))
            Case "2", "h"
                lstResult2.Items.Add(String.Format(fmtstr, "Lawn mower", 12))
            Case "3", "h"
                lstResult2.Items.Add(String.Format(fmtstr, "Paint sprayer", 20))
            Case "1", "f"
                lstResult2.Items.Add(String.Format(fmtstr, "Rug cleaner", 24))
            Case "2", "f"
                lstResult2.Items.Add(String.Format(fmtstr, "Lawn mower", 18))
            Case "3", "f"
                lstResult2.Items.Add(String.Format(fmtstr, "Paint sprayer", 40))
        End Select
        lstResult2.Items.Add(String.Format(fmtstr, "Deposit", 30))
        lstResult2.Items.Add(String.Format(fmtstr, "Total", 25 + 25))
        '-----------------------------------------------------------------------    End Sub
End Class

Make a breakpoint at:
Select Case item.ToUpper & duration.ToUpper

Add to watch:
item.ToUpper & duration.ToUpper

what is the value of:
item.ToUpper & duration.ToUpper

analyze your select statement again or just use IF ELSE IF Statement...

figured it

Did it turn out to be the way you wrote the expression to test?

Select Case item.ToUpper & duration.ToUpper
             Case "1", "h"

The ampersand (&) will do a string concatenation; the ToUpper makes the text uppercase. Therefore, the case should be

Case "1H"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.