私は最終的に別の質問に対する私の答えを見つけたと思いますが、プログラムはこの次のコードを使用した私のフォーマットのいずれも好きではありません。この行をフォーマットする必要があります:
Dim ProductString As String = txtProductID.Text.PadRight(12, " ") & "" & txtDescription.Text.PadRight(50, " ") & "" & txtQuantityAmount.Text.PadRight(7, " ") & "" & txtPriceAmount.Text.PadLeft(9, " ").ToString
具体的には、txtPriceAmount.Text.PadLeft(9, " ").ToString
通貨形式( "C2")を受け入れる必要があります。私は何が間違っているのですか?
Private Sub PurchaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PurchaseToolStripMenuItem.Click
'Test to determine if a product was found.
If txtDescription.Text = String.Empty Then
'Cannot purchase, product was not found
MessageBox.Show("You must select a valid product before purchasing.", "Cannot Purchase", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtProductID.Focus()
txtProductID.SelectAll()
Else
'Can purchase the product
Dim ProductString As String = txtProductID.Text.PadRight(12, " ") & "" & txtDescription.Text.PadRight(50, " ") & "" & txtQuantityAmount.Text.PadRight(7, " ") & "" & txtPriceAmount.Text.PadLeft(9, " ").ToString
lstPurchaseItems.Items.Add(ProductString)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Accumulate the total value of this customer order
'and display it to the output textbox
TotalDueDecimal += (txtPriceAmount.Text.ToString * txtQuantityAmount.Text)
txtTotalDueAmount.Text = TotalDueDecimal.ToString("C2")
'TotalDueTextBox.Text = QuantityTextBox.Text * TotalDueDecimal.ToString("C2")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Accumulate total sales by product to an array
Dim IndexInteger As Integer = cboProductIDLookup.SelectedIndex
ProductSalesTotalDecimal(IndexInteger) += (txtPriceAmount.Text * txtQuantityAmount.Text)
'Here you can clear the form of product info if you think
'that is a good way to do the processing
cboProductIDLookup.SelectedIndex = -1
txtProductID.Clear()
txtDescription.Clear()
txtPriceAmount.Clear()
txtQuantityAmount.Clear()
txtProductID.Focus()
End If
End Sub
txtPriceAmount.Text
数値に変換してから、通貨としてフォーマットする必要があります。
Double.Parse(txtPriceAmount.Text).ToString("C2").PadLeft(9, " ")
txtPriceAmount.Textが数値でない場合、エラーが発生します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加