一時変数と配列を使用してそこに配置されたテキストボックス (価格) の値を取得し、それを 10 進数値に変更して、合計売上高を合計してから合計する方法を見つけようとしています。同じ配列を使用して別のテキスト ボックスからの総重量。私はこれを約 5 時間使用しており、本とオンライン サイトの検索を行っていますが、何も機能していません。プライベート サブ購入ボタンの手順で行き詰まっています (下から 2 番目)。私の合計アイテムカウンターは機能しており、メッセージボックスが機能していることを確認するために、subTotal Decimal および totalWeightDecimal カウンターも作成しましたが、+= 1 を正しいコードに変更したいのですが、見つかりません。パースしてみましたがだめでした。textbox.text を変更して、誰かが見られるようにコード全体を含めました。プライベート変数が多すぎることはわかっていますが、それらを取り除く前に、すべてを理解するのを待っています。どんな助けでも大歓迎です。全体として、このプログラム全体で最低 15 時間費やしました。お時間とご尽力いただきありがとうございます。
'Declare Item Structure.
Structure Item
Dim upcString As String
Dim nameString As String
Dim descriptionString As String
Dim weightString As String
Dim priceDecimal As Decimal
End Structure
'Declare the ItemPrices Structure
Public Structure ItemPrices
Dim itemdescriptionString As String
Dim itempriceDecimal As Decimal
Dim itemweightDecimal As Decimal
Dim itemupcInteger As Integer
End Structure
Public Class lab7Form
Private price1Decimal As Decimal
Private subTotalDecimal As Decimal
Private grandTotalDecimal As Decimal
Private totalDecimal As Decimal
Private totalItemsInteger As Integer
Private MessageString As String
Private totalWeightDecimal As Decimal
Dim myItem As Item
Private ItemPricesArray(3) As ItemPrices
Private Sub exitButton_Click(sender As System.Object, e As System.EventArgs) Handles exitButton.Click
If MsgBox("Click Yes to Exit, Click No to Cancel", MsgBoxStyle.YesNo, "You Decide") = MsgBoxResult.Yes Then
Me.Close()
End If
End Sub
Private Sub clearButton_Click(sender As System.Object, e As System.EventArgs) Handles clearButton.Click
'Clear the textbox values.
upcTextBox.Text = ""
descriptionTextBox.Text = ""
weightTextBox.Text = ""
priceTextBox.Text = ""
End Sub
Private Sub lab7Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Load my itemsListbox with the items for the user.
itemsListBox.Items.Add("Notebook PC")
itemsListBox.Items.Add("Deskjet Printer")
itemsListBox.Items.Add("Color Ink Cartridge")
itemsListBox.Items.Add("Black Ink Cartridge")
'Load the ItemPricesArray values.
ItemPricesArray(0).itemdescriptionString = "Notebook PC"
ItemPricesArray(1).itemdescriptionString = "Deskjet Printer"
ItemPricesArray(2).itemdescriptionString = "Color Ink Cartridge"
ItemPricesArray(3).itemdescriptionString = "Black Ink Cartridge"
ItemPricesArray(0).itempriceDecimal = 1500D
ItemPricesArray(1).itempriceDecimal = 430D
ItemPricesArray(2).itempriceDecimal = 11D
ItemPricesArray(3).itempriceDecimal = 10D
ItemPricesArray(0).itemweightDecimal = 7D
ItemPricesArray(1).itemweightDecimal = 16D
ItemPricesArray(2).itemweightDecimal = 0.5D
ItemPricesArray(3).itemweightDecimal = 0.5D
ItemPricesArray(0).itemupcInteger = 111111111
ItemPricesArray(1).itemupcInteger = 222222222
ItemPricesArray(2).itemupcInteger = 333333333
ItemPricesArray(3).itemupcInteger = 444444444
End Sub
Private Sub itemsListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles itemsListBox.SelectedIndexChanged
descriptionTextBox.Text = itemsListBox.Text
'I am using a table lookup Do/Loop here.
Dim myBoolean As Boolean 'True = I found an items price.
Dim indexInteger As Integer = 0
Do Until myBoolean Or indexInteger > 3
With Me
If .descriptionTextBox.Text = ItemPricesArray(indexInteger).itemdescriptionString Then
.priceTextBox.Text = ItemPricesArray(indexInteger).itempriceDecimal.ToString("C")
.weightTextBox.Text = ItemPricesArray(indexInteger).itemweightDecimal.ToString()
.upcTextBox.Text = ItemPricesArray(indexInteger).itemupcInteger.ToString()
myBoolean = True
Else
indexInteger += 1
End If
End With
Loop
End Sub
Private Sub purchaseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles purchaseButton.Click
Dim DecNumber1 As Decimal
'Parse Numbers
DecNumber1 = Decimal.Parse(priceTextBox.Text)
If purchaseButton.Enabled And priceTextBox.Text <> "" Then
'Calculate the quantities
totalItemsInteger += 1 'I can't figure out how to total up the weights and prices when they are both local variables.
subTotalDecimal += DecNumber1
totalWeightDecimal += 1
'From Page 172 Put together what you want to appear in message boxes
Dim MessageString As String
Dim totalString As String
Dim numberOfItemsString As String
Dim weightOfItemsString As String
numberOfItemsString = totalItemsInteger.ToString()
totalString = subTotalDecimal.ToString("C")
weightOfItemsString = totalWeightDecimal.ToString("N")
MessageString = "Total Items : " & numberOfItemsString &
Environment.NewLine & "Total Weight: " & weightOfItemsString &
Environment.NewLine & "Subtotal: " & totalString
'Display the message box
MessageBox.Show(MessageString, "Items Purchased", MessageBoxButtons.OKCancel)
End If
End Sub
Private Sub totalButton_Click(sender As System.Object, e As System.EventArgs) Handles totalButton.Click
Dim numberofOrdersString As String
If totalButton.Enabled Then
numberofOrdersString = "Number of Orders: " & totalItemsInteger.ToString()
MessageString = "Total Sales: " & grandTotalDecimal.ToString("C")
'Display the message box
MessageBox.Show(MessageString, "Items Purchased", MessageBoxButtons.OKCancel)
End If
End Sub
End Class