2013-04-06 87 views
-2

我有一些麻煩,顯示運費價格爲lblshipping.text指數外界限

Option Explicit On 
Option Strict On 
Option Infer Off 

Public Class frmMain 
    Private intMin() As Integer = {1, 11, 51, 101} 
    Private intMax() As Integer = {10, 50, 100} 
    Private dblShip() As Double = {15, 10, 5, 0} 

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click 
     Me.Close() 
    End Sub 

    Private Sub txtordered_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.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(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtOrdered.TextChanged 
     lblShipping.Text = String.Empty 
    End Sub 

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click 

     Dim intOrdered As Integer 
     Integer.TryParse(txtOrdered.Text, intOrdered) 

     For intIndex As Integer = 0 To 3 
      If intOrdered <= 2 Then 
       If intOrdered >= intMin(intIndex) And intOrdered <= intMax(intIndex) Then 
        lblShipping.Text = dblShip(intIndex).ToString("C2") 
       End If 
      End If 
      If intIndex = 3 Then 
       If intOrdered >= intMin(intIndex) Then 
        lblShipping.Text = dblShip(intIndex).ToString("C2") 
       End If 
      End If 
     Next intIndex 
    End Sub 
End Class 
+0

使你的代碼**最小化**並刪除不必要的文件。發佈** real **代碼(你的使用'Option Strict On'這是很好的,但它不會編譯!)並且**特定**關於錯誤 - 它在哪裏發生?你的代碼很難說清楚。 – 2013-04-06 11:37:36

回答

0

嘗試刪除該聲明

Private Sub txtordered_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtOrdered.TextChanged 
    lblShipping.Text = String.Empty 
End Sub 

,並嘗試改變你的下一語句

For intIndex As Integer = 0 To 3 
     If intOrdered <= 2 Then 
      If intOrdered >= intMin(intIndex) And intOrdered <= intMax(intIndex) Then 
       lblShipping.Text = dblShip(intIndex).ToString("C2") 
      End If 
     elseIf intIndex = 3 Then 
      If intOrdered >= intMin(intIndex) Then 
       lblShipping.Text = dblShip(intIndex).ToString("C2") 
      End If 
     End If 
    Next intIndex 
+0

爲什麼會發生這些變化?這似乎與OP的問題沒有任何關係。 – 2013-04-06 11:41:43

+0

刪除語句>因爲我認爲,如果得到該語句,lbl shipping不會有價值。關於for循環,只是爲了最小化代碼 – Kasnady 2013-04-08 00:51:16