Click here to Skip to main content
14,332,309 members
Rate this:
Please Sign up or sign in to vote.
See more:
when I click the play button it show = System.FormatException: 'Input string was not in a correct format.'

pls try your best to help me

timer1 is a timer from the toolbox

totaltime is a name of my timer,
and a timer is on a label

What I have tried:

namespace my_first_app_dad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            timer1.Start();
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            int number = Int32.Parse(totaltime.Text);
            number =+ 1;

        }
    }
}
Posted
Updated 10-Jul-19 22:21pm
v2
Comments
Gerry Schmitz 10-Jul-19 20:26pm
   
Maybe "totaltime.Text" ain't an int.
Rate this:
Please Sign up or sign in to vote.

Solution 2

This happens because totaltime.Text it is not a compliant string representation of an integer. You might either or
   
Comments
Maciej Los 12-Jul-19 2:14am
   
:thumbsup:
CPallini 13-Jul-19 3:40am
   
Thank you, Maciej!
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can try this.

If(Int.tryparse(totaltime.text, out int number))
{
 int num = number + 1;
 totaltime.text = $"{num}";
}


Let me know if it works for you.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100