'必要条件:txtQuantityおよびtxtUnitCost TextBoxコントロールからユーザーが入力したデータを読み取るCalculateTotalCostというVisual Basicプロシージャを作成します。 CalculateTotalCostプロシージャは、2つのTextBoxコントロールに入力されたテキストを数値に変換する必要があります。次に、2つの数値を組み合わせて、注文数量に基づいて適切な値引きを適用し、lblTotalCost Labelコントロールに結果を表示する必要があります。 次のエラーチェックルールが適用されます。 a。 txtQuantity TextBoxコントロールでユーザーが入力したテキストは、負でない整数を表す必要があります。そうでない場合、プロシージャはlblTotalCost Labelコントロールに "Invalid quantity!"というフレーズを出力する必要があり、それ以上の処理は行われません。 b。 txtUnitCost TextBoxコントロールにユーザーが入力したテキストは、負でないDoubleを表す必要があります。そうでない場合は、lblTotalCost Labelコントロールに「Invalid unit cost!」というフレーズを出力し、それ以上処理する必要はありません。 ユーザー入力エラーがないと仮定すると、lblTotalCost Labelコントロールに表示される適切に割り引かれた合計が現在の形式で表示されます。ディスプレイには、先頭の通貨記号(コンピュータの設定方法によりますが、これはおそらくドル記号になります)と、含まれる小数点の後ろの2つの末尾の数字が含まれている必要があります。なぜ私のコードのelse部分をスキップしていますか?
Public Class Form1
Private Sub lblTotalCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotalCost.Click
'Author: Eric Konga_ 14200694 _BCIT/3_ The Papaua New Guinea University of Technology
' this program will read read user entered data from the two text boxes on the form and
' will calcualte (Multiply) the two numbers together and will then apply the appropriate discount
'based on the quantity ordered, and display the result(Total Cost) in the Label control.
'Declaring Variables as strings. This sets will out put to the screen the appropriate percentages
'based the quantity ordered.
Dim strDiscount As String
Dim strDiscount1 As String
Dim strDiscount2 As String
Dim strDiscount3 As String
Dim strDiscount4 As String
'declaring variables as integer, double and long. this sets of program will output to the screen
'
Dim intQuantity As Integer
Dim dblUnitCost As Double
Dim dblTotalCost As Double
'Assigning Variables
strDiscount = "0%"
strDiscount1 = "20%"
strDiscount2 = "30%"
strDiscount3 = "40%"
strDiscount4 = "50%"
' This is a mathematical calculator that calculates the TotalCost (TC).
intQuantity = txtQuantity.Text
dblUnitCost = txtUnitCost.Text
dblTotalCost = intQuantity * dblUnitCost
If intQuantity <= 9 Then
lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount & _
" Discount."
ElseIf intQuantity <= 19 Then
lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount1 & _
" Discount."
ElseIf intQuantity <= 49 Then
lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount2 & _
" Discount."
ElseIf intQuantity <= 99 Then
lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount3 & _
" Discount."
ElseIf intQuantity >= 100 Then
lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount4 & _
" Discount."
' under this condition, it will only execute if the integer(QTY) is negative or
'the unser entered float(UC) is negative.
Else
lblTotalCost.Text = (" Invalid Quantity!" & " or Ivalid Unit Cost!")
End If
End Sub
End Class
IFでブレークポイントとデバッグを実行すると、intQuantityはどうなるのですか? –