What could be causing my destinationVariable to not update in my timer program?

Click For Summary
SUMMARY

The issue with the "destinationVariable" not updating in the timer program is due to the static variable "myClock" being set to the current timer value immediately before the conditional check. The condition checks if the difference between the current timer and "myClock" exceeds 100, but since "myClock" is updated right before this check, the condition rarely evaluates to true. To resolve this, the program should implement a loop structure to allow for continuous execution without resetting "myClock" immediately after the check.

PREREQUISITES
  • Understanding of Visual Basic syntax and structure
  • Familiarity with timer functions in programming
  • Knowledge of static variables and their behavior
  • Experience with conditional statements and loops
NEXT STEPS
  • Implement a loop structure in Visual Basic to continuously check the timer
  • Research the use of "Do While" or "For" loops in Visual Basic
  • Explore the behavior of static variables in Visual Basic
  • Learn about timer precision and handling in Visual Basic applications
USEFUL FOR

Programmers and developers working with Visual Basic, particularly those troubleshooting timer-related issues and optimizing variable updates in their applications.

angelspikes
Messages
10
Reaction score
0
I've debugged and run my program without seeing any results from my "destinationVariable".
What could be wrong?

sub main()

call myfunction()

end sub

sub myfunction()

static myClock As Single

myClock = timer

if (timer - myClock) > 100 Then
destinationVariable += 1 // This variable is linked to this script
End If

End Sub

// I want the function to run in a loop, but I guess I don't need to use the do loop function to make that happen?
 
Technology news on Phys.org
angelspikes said:
myClock = timer
if (timer - myClock) > 100 Then

Since these lines execute right after each other, I doubt that the "if" test will ever be true unless the program gets interrupted between the two statements. That would be "rare". It may happen occasionally if you put this in a hard loop and run it continuously, but the odds on anyone run are very small.
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
5K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
2K
  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 17 ·
Replies
17
Views
3K