Input string was not in a correct format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Noam Afuta
    New Member
    • Feb 2012
    • 1

    Input string was not in a correct format

    Im trying to convert an string"0" to an int, yet keeps giving me the error "Input string was not in a correct format."

    int befpoints = Convert.ToInt32 (label7.Text);
    int curpoints = befpoints + points;
    label7.Text = Convert.ToStrin g(curpoints);
    label6.Text = '+' + pt;

    any ideas?
  • Samuel Jones
    New Member
    • Jan 2011
    • 48

    #2
    You can use the int.Parse method.
    Code:
    int befpoints = int.Parse(label7.Text)
    Another method is to use the try parse method. This method results in a true or false that states if it was correctly converted. go to .NET Perls - int.TryParse

    You can also use the below method instead of the convert method.
    Code:
    label7.Text = curpoints.ToString()

    Comment

    Working...