Friday 15 July 2011

vb.net - Compile error: A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll -


When it is compiled I get this error message on my form. This form works and runs it as I want, but the error keeps popping up.

Here is my source code:

  Strictly clear on options option New frmCustomRanges Private subtxtMidPointValue_TextChanged (as in this object, as E EventArgs) TxtMidPointValue.TextChanged handles on the class frmEnterMidPoint Dim Obj 'This event runs when the txtMidPointValue is changed. 'It enables the empty button if it is not empty. If txtMidPointValue.Text = "" Then btnClear.Enabled = False Else btnClear.Enabled = True End End Sub manages private sub btnOK_Click (as this object, EventArgs e) btnOK.Click 'event runs When btnOk is pressed. In the process, 'assumes' is entered in the text box and turns into decimal that value is again referred to as 'frmCustomRanges' The mid label process also calculates 'Hourly equivalent' process to the current form ends by closing the 'frmCustomRanges form If IsNumeric (txtMidPointValue.Text) Thereafter dollars annually mark Hourly Obj.lblAnnualMid.Text = decMidPointValue.ToString (displays the results as "C" convert numbers MIN decMidPointValue decimal be = entering decimal, as Convert.ToDecimal (txtMidPointValue.Text) ') Obj.lblHourlyMid.Text = Convert.ToDecimal (decMidPointValue / 52/40) .ToString (' C ') as off existing Me .Close () 'Open frmCustomRanges Obj.ShowDialog () else MsgBox ( "you entered into a non--numeric value. Please enter a value check and again", vbCritical, "input error") with txtMidPointValue .text = "Focus" ends end with end sub personal sub-btnClear_Click (as in this object, as E EventArgs) manages btnClear. Click 'BTN Clear This event runs when clicked. 'Event clears the text box and foucs sends' txtMidPointValue .text = "" .focus (with back to the text box) ending with the end sub personal sub btnCancel_Click (as the object, in the form of e EventArgs ) Handle btnCancel.Click 'It also runs when BTNcannel is clicked' the process closes the current form and opens the 'custom range form'. 'Close existing form' Measure the custom bounds form Obj.ShowDialog (Open) End Sub Ending Class    

You can use Decimal.TryParse - IsNumeric () is not the best option for checking if something is a number that you can use

  private sub bnOK_Click (this. as in kind, e EventArgs) handles bnOK.Click dim decMidPointValue decimal if Decimal.TryParse (txtMidPointValue.Text, decMidPointValue) as the 'decMidPointValue parsed values. Obj.lblAnnualMid.Text = decMidPointValue.ToString ( 'C') Obj.lblHourlyMid.Text = (decMidPointValue / 52/40) .ToString ( 'C') 'More code ... or' parsed as a decimal can go; DecMidPointValue is Zero 'Notify the user End End End Sub    

No comments:

Post a Comment