loop not looping
-
- 5StarLounger
- Posts: 626
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: loop not looping
I have had better success distributing global templates locally. Updates are downloaded as part of the user login to the network.
(My experience with this is not recent, though.)
(My experience with this is not recent, though.)
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: loop not looping
Hi Ken.stuck wrote: ↑09 Dec 2020, 12:41That approach is on the 'to do' list. MS Teams allows me to both see and control a remote PC. Seeing Is OK but controlling is a bit like stirring concrete.ChrisGreaves wrote: ↑08 Dec 2020, 16:45...a possibility, for you to single-step through the code remotely?...
If I understand this, you would be allowed linked-computers, but YOU would be reduced to using a voice-telephone to say "Now please click on the little yellow thingy just below the line that reads "lngCopied = lngCopyImages(strLatest, strFolder, strMonth)", and hope that your correspondent wasn't too shaky at the finger tips.
A further thought comes to mind: It seems that, at this time, the "loop not looping" has not brought the corporation to its knees.
Why not release the next updated version with a piece of code that, unless disabled by the loop, displays a graphic on the screen? You could have fun writing a bit of graphics code that showed a disk drive changing from Blue to Crimson, from the bottom up, and stop it with a
Code: Select all
MsgBox.Sub test()
lng = MsgBox("", vbSystemModal + vbAbortRetryIgnore)
End Sub
(My Rant appears to have cleared up)
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.
-
- Panoramic Lounger
- Posts: 8185
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: loop not looping
Yesterday I was allowed to meet on-site with the problem laptop (and its user). With it in front of me I was able to identify that the bit of the macro that was failing involved a copy & paste. It was weird.
If I put a break point one the line above the 'bad' bit and then use F8 to step through then next three lines, it worked as expected. I could then allow the code to run to the end, whereon it would loop and stop again at the break point. Once again using F8 allowed it to get over the next three lines and then away it run, loop and stop again at the break point. Rinse and repeat. BUT as soon as I removed the breakpoint the code would run through the 'bad' bit once and then stop executing. No error message, just stop.
Having got this far, the user then sort of hinted that they had fiddled with the cut, copy, paste settings In File | Options | Advanced. However, even given this new clue I could not find any differences between what those settings showed on the problem laptop compared to the same settings on my 'good' laptop.
At this point the IT people swapped the problem machine for another one. Once I'd tweaked the necessary settings on that machine, so it would find the global template that holds the code, everything worked as expected.
So. in summary, the user did something that broke the set up on his laptop but for the life of me I could not figure out exactly what they had done. The problem was resolved by the nuclear option of swapping the problem machine for a different one, one that had not been poked at by a user. This means the problem is fixed, at least until the user does something to break it again.
Ken
If I put a break point one the line above the 'bad' bit and then use F8 to step through then next three lines, it worked as expected. I could then allow the code to run to the end, whereon it would loop and stop again at the break point. Once again using F8 allowed it to get over the next three lines and then away it run, loop and stop again at the break point. Rinse and repeat. BUT as soon as I removed the breakpoint the code would run through the 'bad' bit once and then stop executing. No error message, just stop.
Having got this far, the user then sort of hinted that they had fiddled with the cut, copy, paste settings In File | Options | Advanced. However, even given this new clue I could not find any differences between what those settings showed on the problem laptop compared to the same settings on my 'good' laptop.
At this point the IT people swapped the problem machine for another one. Once I'd tweaked the necessary settings on that machine, so it would find the global template that holds the code, everything worked as expected.
So. in summary, the user did something that broke the set up on his laptop but for the life of me I could not figure out exactly what they had done. The problem was resolved by the nuclear option of swapping the problem machine for a different one, one that had not been poked at by a user. This means the problem is fixed, at least until the user does something to break it again.
Ken
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop not looping
If this or a similar problem ever pops up again, you might try inserting a line
DoEvents
in one or more places inside the loop. That might solve timing problems.
DoEvents
in one or more places inside the loop. That might solve timing problems.
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: loop not looping
Oops! Hans beat me by 6 minutes!
I use it like North Americans use ketchup.
Cheers
Chris
DoEvents any good for you?stuck wrote: ↑16 Dec 2020, 15:12If I put a break point one the line above the 'bad' bit and then use F8 to step through then next three lines, it worked as expected. I could then allow the code to run to the end, whereon it would loop and stop again at the break point. Once again using F8 allowed it to get over the next three lines and then away it ran, loop and stop again at the break point. Rinse and repeat. BUT as soon as I removed the breakpoint the code would run through the 'bad' bit once and then stop executing. No error message, just stop.
I use it like North Americans use ketchup.
Cheers
Chris
He who plants a seed, plants life.
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: loop not looping
Yes, sprinkling DoEvents throughout the code often makes it taste much better
StuartR
-
- Panoramic Lounger
- Posts: 8185
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: loop not looping
Thanks, I'll look into DoEvents but I still think this was a user-forced problem as it was just this one machine that was choking on this code.
Ken
Ken
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop not looping
I don't dispute that, but there is a chance that DoEvents would have made the code run on the user's original laptop.
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: loop not looping
I think that the Good news out of this is that your code works, and the Evil User is now on record as having tampered with the system to the point where a corporate-sponsored/funded program failed to operate correctly.
You come up looking good and the user has been put on a mild form of notice.
ENJOY YOUR WELL EARNED CHRISTMAS BREAK.
But only from paid work, not from Eileen's Lounge!
Cheers
Chris
He who plants a seed, plants life.
-
- 5StarLounger
- Posts: 626
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: loop not looping
@HansV
Thank you for the idea to use DoEvents.
I've been working for more than a month of-and-on on a problem (mostly off) that this solved.
It is in an AutoExec code that kept throwing an error during loading but would not throw the same error when run after Word is open. I was trying to resize task panes but no document was open when it was trying to run the code.
Thank you for the idea to use DoEvents.
I've been working for more than a month of-and-on on a problem (mostly off) that this solved.
It is in an AutoExec code that kept throwing an error during loading but would not throw the same error when run after Word is open. I was trying to resize task panes but no document was open when it was trying to run the code.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- Administrator
- Posts: 7213
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: loop not looping
Just as a BTW, I had a similar-ish problem running code in an Excel application (getting data via RS485 and saving to disk) which I crudely resolved by adding a one second delay into a loop. The only reason I could think of was that the user had upgraded to a faster laptop with SSD, and the 'natural' delay caused by writing to a HDD had disappeared...
Leif
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: loop not looping
If people are into trying a few DoEvents, then it might be worth noting that a double pair of DoEvents, like
DoEvents:DoEvents
has been known to mysteriously solve problems.
DoEvents are very cheap, so if you are into sprinkling a few around, it does not do to economise.
If you find a liberal sprinkling of DoEvents, double at that, solves your problem, then you can always remove them one by one until you find the one or two or four that did the job
Alan
DoEvents:DoEvents
has been known to mysteriously solve problems.
DoEvents are very cheap, so if you are into sprinkling a few around, it does not do to economise.
If you find a liberal sprinkling of DoEvents, double at that, solves your problem, then you can always remove them one by one until you find the one or two or four that did the job
Alan
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop not looping
They do slow down a loop considerably, though. This is what you want if you suspect timing problems, of course. But don't use more than you need.Doc.AElstein wrote: ↑22 Dec 2020, 18:52DoEvents are very cheap, so if you are into sprinkling a few around, it does not do to economise.
Code: Select all
Sub Test1()
Dim t As Single
Dim i As Long
t = Timer
For i = 1 To 1000000
Next i
t = Timer - t
Debug.Print t
End Sub
Code: Select all
Sub Test2()
Dim t As Single
Dim i As Long
t = Timer
For i = 1 To 1000000
DoEvents
Next i
t = Timer - t
Debug.Print t
End Sub
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: loop not looping
Is it possible that in the code without DoEvents VBA is optimising the loop away, but with the DoEvents it has to actually loop?
Could you add debug.print i in both loops and see what the timings are
Could you add debug.print i in both loops and see what the timings are
StuartR
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: loop not looping
I tested this myself with either one or two DoEvents in the loop. It looks like each DoEvent takes about .000011 seconds
11.41406
5.703125
Code: Select all
Sub Test2()
Dim t As Single
Dim i As Long
t = Timer
For i = 1 To 100000
DoEvents
DoEvents
Next i
t = Timer - t
Debug.Print t
End Sub
Code: Select all
Sub Test1()
Dim t As Single
Dim i As Long
t = Timer
For i = 1 To 100000
DoEvents
Next i
t = Timer - t
Debug.Print t
End Sub
StuartR
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop not looping
So it doesn't make a lot of difference if your loop is executed hundreds or thousands of times, but you'll notice it if the loop is executed millions of times.
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: loop not looping
Ooooh!
I love this line of thought!
Cheers
Chris
He who plants a seed, plants life.
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe