I recieve the following message when i try to compile my program, and I dont know what it means!
I am trying to make it so when the user enters a number with the percent sign (10%) into my text box the program will treat it like 10.0
Here are parts of my code
and here is the part where the error is occuring
The bluw text above is where the error is occuring
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "10%" to type 'Single' is not valid.
I am trying to make it so when the user enters a number with the percent sign (10%) into my text box the program will treat it like 10.0
Here are parts of my code
Code:
Private Sub txtFederal_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFederal.Validating
'Vaildates that a number has been entered into the text box
If Not IsNumeric(Val(txtFederal.Text)) Then
MessageBox.Show("Federal taxes must be a number.", "Invaild Input", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
'Select the existing text in the text box.
txtFederal.SelectionStart = 0
txtFederal.SelectionLength = txtFederal.Text.Length
'Set the e.Cacel to true so the focus will stay in the control
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
and here is the part where the error is occuring
Code:
Sub InputData(ByRef empName As String, ByRef hrRate As Single, ByRef hrsWorked As Single, ByRef fedTax As Single, ByRef ficaTax As Single, ByRef stateTax As Single)
' Get payroll data for employee
empName = txtName.Text
hrRate = CInt(txtRate.Text)
hrsWorked = CInt(txtHours.Text)
[COLOR=blue]fedTax = CSng(txtFederal.Text)[/COLOR]
ficaTax = CSng(txtFica.Text)
stateTax = CSng(txtState.Text)
The bluw text above is where the error is occuring