last day (15 days later) » 

8:23 PM
0
Q: VB.NET Timer stops working after it ticks the first time

CrazyCraft316the timer in my code stops working after the first tick, I have it set to start ticking every second when the form loads: Private Sub FormIdleTimeWaster_Load(sender As Object, e As EventArgs) Handles MyBase.Load timerCPS.Interval = 1000 timerCPS.Start() End Sub but after the firs...

 
Why are you restarting it again in the tick event? If you take that out what happens?
 
@Hursey i am creating an idle/clicker game so I need to program to add the current CPS(Clicks per Second) to the total Clicks (HWTotal) every second
 
Please understand that what you've shown us does not demonstrate your problem. You also say that "nowhere else refrences my code" which is clearly wrong. Can you please show all of your code relating to TimerCPS? You need to get all of the code behind too.
 
@Hursey Sorry i missed some infomation, this is my first question ive asked here. i have included all the code in my program that includes timerCPS already in the question, (so far its very simple). what do you mean by the code behind it? do you mean i need to include all the code that includes CPS and HWTotal to? Edit - I Updated the Question so the last line is more clear
 
@CrazyCraft316 - You should always respond to one person at a time.
@CrazyCraft316 - When you drag and drop components onto a form, Visual Studio creates code in a separate file that instantiates and configures your components. The Timer class must have this code. You need to show that.
@CrazyCraft316 - And can you confirm whether this code is about VB.NET or about VBA? The two are different and distinct.
 
8:23 PM
@Enigmativity my bad, I thought that VB.NET was an extention of VBA, the code is in VB.NET (i will fix the tag now), and here is the code from the IdleTimeWaster.Aplication.vb file. do you mean this? Friend WithEvents timerCPS As Timer
 
@CrazyCraft316 - And, also, can you confirm if you're using System.Timers.Timer as your timer?
@CrazyCraft316 - Yes, please show all the code related to timerCPS.
 
@Enigmativity that was another thing that i thought was the same, its using this Me.timerCPS = New System.Windows.Forms.Timer(Me.components)
 
@CrazyCraft316 - Yes, all code relating to timerCPS - where it's created and configured as well as the code where you use it. Everything please.
 
@Enigmativity i will edit the Question to include all of that then Edit- i edited it
 
How do you know it's not working?
 
8:23 PM
@LarsTech What's meant to happen is that every second the code adds the current clicks per second (CPS) to the total clicks (HWTotal) and display that into the form, when i run the program it adds CPS to HWTotal only once and doesn't do it again
 
Regardless of everything else here, you still have timerCPS.Start() in the timerCPS.Tick event handler. Best case that is pointless because the only way that is going to be executed is because timerCPS has already been started, Worse case, your going to get unpredictable results.
 
Where are you incrementing CPS?
 
@Hursey i added timerCPS.Start() into the timerCPS.Tick event in an attempt to fix the timer stopping, I will remove it because it doesn't actually help then
@LarsTech I am creating an Idle/clicker game and found this as a way to run a piece of code every second
 
I think you misunderstand what the Tick event is doing. It is running your code every interval. Try adding CPS = CPS + 1 in your Tick code.
 
@LarsTech i will see if that fixes it for now, then later when i add upgrades so the program increases the CPS i can try add it back in
@Hursey honestly this is the first time I've used timers in VB.NET so I'm not sure
 
8:23 PM
Have you done any debugging, for an example put a breakpoints in the timer event, inspected the status of your timer at various points etc?
 
@Hursey i thought i did when i double checked before posting the question but apparently i didn't debug (i wanted to try avoid this but somehow forgot to add breakpoints and try that). i did that and the timer is running like its meant to and repeating but its something else that's the problem. sorry for wasting everyone's time. thanks for the help everyone and the knowledge i have gained for the next time i ask a question. sorry again that adding breakpoints went over my head somehow (i must be tired or something)
 

last day (15 days later) »