I am working on an application that calculates a shipping price based on the amount ordered. I have a 2D array (or so I believe) that I am searching, however it only yields any results when I search for an exact number. I would like to set it so when I search a value between 1 and 10 I get a $15 for shipping. Right now I have to enter 1 to receive the $15 shipping, 11 for $10, and so on. Below is what I have so far.
I have tried playing with the columns and rows to no avail. Some assistance would be greatly appreciated.Code:Public Class frmMain Private strItems(,) As String = {{"1", "15"}, {"11", "10"}, {"51", "5"}, {"101", "0"}} Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub Private Sub txtordered_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtOrdered.KeyPress ' allows the text box to accept numbers and the Backspace key If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then e.Handled = True End If End Sub Private Sub txtordered_TextChanged(sender As Object, e As EventArgs) Handles txtOrdered.TextChanged lblShipping.Text = String.Empty End Sub Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click Dim strSearchForId As String Dim intRow As Integer strSearchForId = txtOrdered.Text Do Until intRow > strItems.GetUpperBound(0) OrElse strSearchForId = strItems(intRow, 0) intRow += 1 Loop If intRow <= strItems.GetUpperBound(0) Then Dim intPrice As Integer Integer.TryParse(strItems(intRow, 1), intPrice) lblShipping.Text = intPrice.ToString("C0") End If End Sub End Class
I am using a textbox to enter in my search value and a label to display the shipping cost.




Reply With Quote
