Aaron Aaron - 1 year ago 66
Vb.net Question

Visual basic 2010 Error

I keep getting an error on fee.ToString("C") when trying to run the code. The error I keep getting is Value of type 'String'cannot be converted to 'System.Windows.Forms.Textbox'. Not sure what I am doing wrong any help I could get would be greatly appreciated. My code is below.

Private Sub calcButton_Click(sender As Object, e As EventArgs) Handles calcButton.Click

Dim bailInt As Integer
Dim collItem As String

Dim fee As Decimal = CDec(0.0)

'Convert input to values
bailInt = Integer.Parse(bailAmountTextBox.Text)
collItem = collateralTextBox.Text

'Calculate 10% fee on bail amount
fee = CDec(0.1 * bailInt)

'Display Messagebox with fee amount
amountDueTextBox = fee.ToString("C")

Catch ex As Exception
MessageBox.Show("Must be numeric data", "Bad Data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With bailAmountTextBox
End With

End Try
End Sub

Answer Source

amountDueTextBox.Text = fee.ToString("C") try this. Your trying to assign a textbox to a string.