나는 finnaly가 다른 질문에 대한 나의 답을 찾았지만, 다음 코드를 가진 어떤 형식의 프로그램처럼 생각한다. 나는이 줄을 포맷해야합니다통화 형식을 설정하는 방법
Dim ProductString As String = txtProductID.Text.PadRight(12, " ") & "" & txtDescription.Text.PadRight(50, " ") & "" & txtQuantityAmount.Text.PadRight(7, " ") & "" & txtPriceAmount.Text.PadLeft(9, " ").ToString
특히, 내가 통화 형식 ("C2")을 받아 txtPriceAmount.Text.PadLeft(9, " ").ToString
이 필요합니다. 내가 도대체 뭘 잘못하고있는 겁니까?? txtPriceAmount.Text가 숫자가 아닌 경우
Double.Parse(txtPriceAmount.Text).ToString("C2").PadLeft(9, " ")
당신은 오류가 발생합니다 :
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
("C2")로 변경하면이 오류가 발생합니다. 문자열 "C2"에서 유형 '정수'로의 변환이 유효하지 않습니다. –
읽을 수 있고 컴파일되는 코드를 게시하는 방법은 어떻습니까? 당신이 올린 글을 다시 포맷 할 수는 없어요. 왜냐하면 "...."은 무엇이든지 –
이 그것을 읽을 수있는 질문을 명확히하는 방법을 모르기 때문입니다. 파란 상자의 코드가 컴파일됩니다. –