我真的很讨厌使用数组。我有一个二维数组,但无法弄清楚如何使用并行一维数组。 “显示运输”按钮的“单击偶数”应根据用户输入的项目数显示运费。我将最小订单金额和运费存储在并行数组中。我无法让计算正常工作。任何帮助表示赞赏。
Public Class frmMain
'declare parallel arrays
Private strNums() As String = {"1", "11", "51", "101"}
Private intShipping() As Integer = {15, 10, 5, 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
'displays the shipping price based on orders
Dim strSearchForNum As Integer
Dim intSub As Integer
Integer.TryParse(txtOrdered.Text, strSearchForNum)
'search the array for the orders greater than zero
'if less than zero show error message
'otherwise display shipping charge
Do Until intSub >= strNums.Length OrElse
strSearchForNum >= CDbl(strNums(intSub))
intSub += 1
Loop
If strSearchForNum = 0 Then
MessageBox.Show("Please enter a number greater than 0", "Number of Orders")
Else
lblShipping.Text = intShipping(intSub).ToString("C2")
End If
txtOrdered.Focus()
End Sub
End Class