Jenny Mchammer
Jenny Mchammer

Reputation: 95

How do I reset switch case?

public void Console(List<Keys> keys)
        {
            clickNo ++;

            start = DateTime.Now;
            progressBar1.Maximum = 1;
            progressBar1.Step = 1;
            progressBar1.Value = 0;

            switch (clickNo)
            {
                case 1:
                    DoRequest(ScreenshotRequest.DannysCommands.NormalOperation); break;
                case 2:
                    DoRequest(ScreenshotRequest.DannysCommands.Displayoverlays); break;
                case 3:
                    DoRequest(ScreenshotRequest.DannysCommands.Dontdisplayoverlays); break;
            }

        }

clickNo is global int variable. I make the three cases in this case it's by using the keys CTRL + G

But I want that after three times if I make again CTRL + G it will start over again case 1 case 2 case3 ...

Now after the third case it's not doing anything.

Upvotes: 0

Views: 1742

Answers (2)

Ronan Thibaudau
Ronan Thibaudau

Reputation: 3603

public void Console(List<Keys> keys)
        {
            clickNo ++;

            start = DateTime.Now;
            progressBar1.Maximum = 1;
            progressBar1.Step = 1;
            progressBar1.Value = 0;

            switch (clickNo)
            {
                case 1:
                    DoRequest(ScreenshotRequest.DannysCommands.NormalOperation); 
                    break;
                case 2:
                    DoRequest(ScreenshotRequest.DannysCommands.Displayoverlays); 
                    break;
                case 3:
                    DoRequest(ScreenshotRequest.DannysCommands.Dontdisplayoverlays); 
                    clickNo = 0;
                    break;
            }

        }

Just set to 0 in the last case.

Upvotes: 1

CodeCaster
CodeCaster

Reputation: 151604

You could reset the counter after the last case:

case 3:
    DoRequest();
    clickNo = 0;
    break;

Upvotes: 4

Related Questions