0

EDITED:

i am writing an autoclicker and its almost done but it has a weird problem...

in btnStart event i have written:

if (listViewPositions.Items.Count == 1)
{
    ClickIntervalStr1 = (listViewPositions.Items[(1) - 1].SubItems[(3) - 1].Text).ToString();
    ClickIntervalNum1 = Convert.ToInt32(ClickIntervalStr1);
    LeftOrRightClickStr1 = (listViewPositions.Items[(1) - 1].SubItems[(4) - 1].Text)
        .ToString();
    SingleOrDoubleClickStr1 = (listViewPositions.Items[(1) - 1].SubItems[(5) - 1].Text)
        .ToString();
}

and in timer (clickprocess) i have written:

timerClickProcessStopAfterXTimes.Interval = ClickIntervalNum1;

but when i press start button it gets this error: "Value '0' is not a valid value for interval. interval must be greater than 0."

i am sure everything is ok but why is this error shows up?!

here is the pictures:

enter image description here

enter image description here

enter image description here

please help...

FIXED:

i just had to write 4 lines of codes of listViewPositions.Items.Count == 1 to listViewPositions.Items.Count == 2 too and also others...

hamidrezas120
  • 35
  • 1
  • 8
  • 2
    If a timer *would allow a value of 0* what would the tick be on? The timer raises an event depending on that value... `The value must be greater than zero, and less than or equal to MaxValue. The default is 100 milliseconds.` – Trevor Jan 24 '20 at 19:12
  • Are you wanting to to be 0, or is the issue that it should be 100 but your int version is showing 0? – JNevill Jan 24 '20 at 19:15
  • @Çöđěxěŕ i know but look at the first picture... its when i click start button and the third picture is the action after start button codes in a timer – hamidrezas120 Jan 24 '20 at 19:15
  • 1
    Why are you writing `Items[(1) - 1]` instead of `Items[0]`? – Rufus L Jan 24 '20 at 19:16
  • @JNevill yes.. as the picture 1 it is 100 and i want the program to set the interval to 100 – hamidrezas120 Jan 24 '20 at 19:17
  • @Rufus L i just wanted to not be confused! :| – hamidrezas120 Jan 24 '20 at 19:18
  • 1
    Not sure why `(1) - 1` is less confusing than `0`...you've introduced unnecessary bracing and an extra operation to the code. Also, why are you calling `.ToString` on the `.Text` property, when it's already a `string`? The first line could be simplified to: `ClickIntervalStr1 = listViewPositions.Items[0].SubItems[2].Text;` – Rufus L Jan 24 '20 at 19:19
  • @Rufus L oh you are right xD i know im not pro yet sorry for that! – hamidrezas120 Jan 24 '20 at 19:20
  • 1
    Are you sure you are hitting the code shown in image #1? `listViewPositions.Items.Count` does not appear to be 1, considering the fact that the listview holds 3 lines in the screenshot (image #2). Use the debugger. – Ruud Helderman Jan 24 '20 at 19:32
  • @Ruud Helderman holy.... i found out why its showing this error!! – hamidrezas120 Jan 24 '20 at 19:37
  • @Ruud Helderman i had to write 4 lines of codes of `listViewPositions.Items.Count == 1` to `listViewPositions.Items.Count == 2` too and also others... – hamidrezas120 Jan 24 '20 at 19:38
  • @Ruud Helderman you are the one who helped me fix this thank you very much!! <3 – hamidrezas120 Jan 24 '20 at 19:39

1 Answers1

2

"Value '0' is not a valid value for interval. interval must be greater than 0."

The obvious reason is because of ClickIntervalNum1 = Convert.ToInt32(ClickIntervalStr1);. The value of ClickIntervalStr1 is evident of 0...

Microsoft has this to say about the Interval property:

The time, in milliseconds, between Elapsed events. The value must be greater than zero, and less than or equal to MaxValue. The default is 100 milliseconds.

To fix this, just make sure it's greater than 0... (simple example):

 timerClickProcessStopAfterXTimes.Interval = ClickIntervalNum1 > 0 ? ClickIntervalNum1 : 100;

References:

Timer.Interval Property System.Timers

Trevor
  • 7,777
  • 6
  • 31
  • 50