I'm having trouble putting in error messages for a selected index. I have a list box that has 5 products in it and I have a numeric up down that goes up to 5. Each product in my inventory has a limited quanity. When the user goes over the limit I would like the error message to display. Heres what I have so far. My Products are steamread into my listbox.
The code below is what I'm tried so far and it didnt work I just want to make it so that if the user goes over the numeric up down on certain products and error message pops up. Any help would be nice thanks.

Select Case CStr(lstproducts.SelectedIndex)
                Case CStr(0) > nudQuantity.Value=2
    MsgBox("Out of Product", MsgBoxStyle.Critical)           
                Case CStr(1) > nudQuantity.value=5
    MsgBox("Out of Product", MsgBoxStyle.Critical)
                Case CStr(2)> nudQuantity.value=3
    MsgBox("Out of Product", MsgBoxStyle.Critical)
                Case CStr(3)>nudQuantity.value=4
    MsgBox("Out of Product", MsgBoxStyle.Critical)
                Case CStr(4)>nudQuantity.value=6 
    MsgBox("Out of Product", MsgBoxStyle.Critical)
            End Select
Public Class Form1
    Structure ProductRecord
        Dim strProduct As String
        Dim intQuantity As Integer
        Dim sngPrice As Single
    End Structure
    Dim ProRec(10) As ProductRecord
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        ' End the application
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim intIndex As Integer
        Dim strFileNameIn As String

            btnPrint.Enabled = False
            Dim Reader As New IO.StreamReader("C:\products.txt")
            strFileNameIn = "products.txt"
            intIndex = 0

            Do Until Reader.Peek = -1
                With Reader
                    ProRec(intIndex).strProduct = .ReadLine()
                    ProRec(intIndex).intQuantity = CInt(.ReadLine())
                    ProRec(intIndex).sngPrice = CSng(.ReadLine())
                End With

                intIndex += 1

            lstProducts.SelectedIndex = 0
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error in Reading file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub

    Private Sub lstProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChanged
        lblPrice.Text = ("$") & CStr((ProRec(lstProducts.SelectedIndex).sngPrice))
    End Sub

    Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click
        Dim outputfile As StreamWriter

        outputfile = AppendText("C:\outputfile.txt")
        lblItems.Text = ProRec(lstProducts.SelectedIndex).strProduct
        lblCost.Text = ("$") & CStr(CSng(lblPrice.Text) * nudQuantity.Value)
        btnOrder.Enabled = False
        btnPrint.Enabled = True

    End Sub
10 Years
Discussion Span
Last Post by MehdiAnis

A list box item has Text Member and Value Member. When you are adding item into the listbox, you have to set the TEXT property to the name of the product and VALUE propertry to the inventory number.

when you do case, you case against the VALUE member like

SELECT CASE lstpeoducts.SelectedItem.VALUE
Case 1: msgbox...
Case 2: msgbox..

that's the idea.

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.