Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Visual Basic How do I get the following text fields to display as Currency? txtP

ID: 3845721 • Letter: V

Question

Visual Basic

How do I get the following text fields to display as Currency?

txtPhoneSubTotal

txtTax

txtPhoneTotal

txtOptions

txtPackageCharge

txtTotalMonthlyCharge

.

.

Here is the code:

'

'

Public Class frmIndividualPlan
    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim frmCellPhonePackages As New frmCellPhonePackages()
        If radModel100.Checked = True Then
            txtPhoneSubTotal.Text = frmCellPhonePackages.ModelCost(0)
            txtTax.Text = (CDbl(txtPhoneSubTotal.Text) * 0.06)
            txtPhoneTotal.Text = txtPhoneSubTotal.Text + txtTax.Text
        ElseIf radModel110.Checked = True Then
            txtPhoneSubTotal.Text = frmCellPhonePackages.ModelCost(1)
            txtTax.Text = (CDbl(txtPhoneSubTotal.Text) * 0.06)
            txtPhoneTotal.Text = txtPhoneSubTotal.Text + txtTax.Text
        ElseIf radModel200.Checked = True Then
            txtPhoneSubTotal.Text = frmCellPhonePackages.ModelCost(2)
            txtTax.Text = (CDbl(txtPhoneSubTotal.Text) * 0.06)
            txtPhoneTotal.Text = txtPhoneSubTotal.Text + txtTax.Text
        End If

        If rad800Pack.Checked = True Then
            If cboEmail.Checked = True Then
                If cboTextMessaging.Checked = True Then
                    txtOptions.Text = frmCellPhonePackages.OptionCost(0) + frmCellPhonePackages.OptionCost(1)
                    txtPackageCharge.Text = frmCellPhonePackages.PackageCost(0)
                    txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
                Else
                    txtOptions.Text = frmCellPhonePackages.OptionCost(0)
                    txtPackageCharge.Text = frmCellPhonePackages.PackageCost(0)
                    txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
                End If

            ElseIf cboTextMessaging.Checked = True Then
                txtOptions.Text = frmCellPhonePackages.OptionCost(1)
                txtPackageCharge.Text = frmCellPhonePackages.PackageCost(0)
                txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
            Else
                txtOptions.Text = 0
                txtPackageCharge.Text = frmCellPhonePackages.PackageCost(0)
                txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
            End If
        End If

        If rad1500Pack.Checked = True Then
            If cboEmail.Checked = True Then
                If cboTextMessaging.Checked = True Then
                    txtOptions.Text = frmCellPhonePackages.OptionCost(0) + frmCellPhonePackages.OptionCost(1)
                    txtPackageCharge.Text = frmCellPhonePackages.PackageCost(1)
                    txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
                Else
                    txtOptions.Text = frmCellPhonePackages.OptionCost(0)
                    txtPackageCharge.Text = frmCellPhonePackages.PackageCost(1)
                    txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
                End If
            ElseIf cboTextMessaging.Checked = True Then
                txtOptions.Text = frmCellPhonePackages.OptionCost(1)
                txtPackageCharge.Text = frmCellPhonePackages.PackageCost(1)
                txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
            Else
                txtOptions.Text = "0"
                txtPackageCharge.Text = frmCellPhonePackages.PackageCost(1)
                txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
            End If
        End If

        If radUnlimited.Checked = True Then
            If cboEmail.Checked = True Then
                If cboTextMessaging.Checked = True Then
                    txtOptions.Text = frmCellPhonePackages.OptionCost(0) + frmCellPhonePackages.OptionCost(1)
                    txtPackageCharge.Text = frmCellPhonePackages.PackageCost(2)
                    txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
                Else
                    txtOptions.Text = frmCellPhonePackages.OptionCost(0)
                    txtPackageCharge.Text = frmCellPhonePackages.PackageCost(2)
                    txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
                End If
            ElseIf cboTextMessaging.Checked = True Then
                txtOptions.Text = frmCellPhonePackages.OptionCost(1)
                txtPackageCharge.Text = frmCellPhonePackages.PackageCost(2)
                txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
            Else
                txtOptions.Text = "0"
                txtPackageCharge.Text = frmCellPhonePackages.PackageCost(2)
                txtTotalMonthlyCharge.Text = CDbl(txtOptions.Text) + CDbl(txtPackageCharge.Text)
            End If
        End If
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class

Explanation / Answer

You can display the text field value as currency by two ways :

1. txtPhoneSubTotal.Text = FormatCurrency(txtPhoneSubTotal.Text)

2.

dim val as Decimal

if Decimal.TryParse(txtPhoneSubTotal.Text.Trim(), val) then

txtPhoneSubTotal.Text = val.ToString("c")

end if

Apply this techniques in your code. :)