Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set format for currency
    primarykey
    data
    text
    <p>I think I have finnaly found my answer to different question but the program doest like any of my formats with this following code. I need to format this line:</p> <p><code>Dim ProductString As String = txtProductID.Text.PadRight(12, " ") &amp; "" &amp; txtDescription.Text.PadRight(50, " ") &amp; "" &amp; txtQuantityAmount.Text.PadRight(7, " ") &amp; "" &amp; txtPriceAmount.Text.PadLeft(9, " ").ToString</code></p> <p>Specifically, I need <code>txtPriceAmount.Text.PadLeft(9, " ").ToString</code> to accept currency Format ("C2"). What am I doing wrong??</p> <pre><code> 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, " ") &amp; "" &amp; txtDescription.Text.PadRight(50, " ") &amp; "" &amp; txtQuantityAmount.Text.PadRight(7, " ") &amp; "" &amp; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload