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
Me.Close()
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
Try
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())
lstProducts.Items.Add(ProRec(intIndex).strProduct)
End With
intIndex += 1
Loop
lstProducts.SelectedIndex = 0
Reader.Close()
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)
outputfile.WriteLine(lblItems.Text)
outputfile.WriteLine(lblCost.Text)
outputfile.Close()
btnOrder.Enabled = False
btnPrint.Enabled = True
End Sub