×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Use of Timer control

Use of Timer control

Use of Timer control

(OP)
Dear colleagues:

The code bellow (intended to create a phantom effect - a text diving from above to bellow) is in the Click event of a Command button:

CODE -->

thisform.MyText.Caption="Hello Word!"

FOR Position=200 TO 380 SKIP 10
	thisform.MyText.Top = Position
	thisform.MyText.Visible = .T.

	FOR MyCounter=1 TO 80000     && Just count to 80000 before 
	NEXT MyCounter               && cleaning MyText on the form 

	thisform.MyText.Visible = .F.
NEXT Position
thisform.MyText.Visible= .F. 

It works fine (in my computer, a 2.61Ghz processor). But I think that is a processor with a greater speed it will not show the effect.

I know that I may (or must?) use the Timer control instead of the FOR...NEXT (used in the code above), but ... how?

Thank you,
SitesMasstec

RE: Use of Timer control

You could use a timer, but in this case, the API Sleep function would be easier.

Do this once:

CODE

DECLARE Sleep IN kernel32 INTEGER dwMilliseconds 

And then do this inside your loop:

CODE

Sleep(1000)  && pauses for 1 second, adjust to what you need 

Tamar

RE: Use of Timer control

(OP)
Hello Tamar!

Thank you, and nice to hear from you!

I used all the code you provided inside the the Click event of a Command button:

CODE -->

DECLARE Sleep IN kernel32 INTEGER dwMilliseconds 
or must I put the above in the Init or PRG (which calls the form) ??


I use Sleep(3) to have the desired effect (the same obtained using just in my computer):

CODE -->

FOR MyCounter=1 TO 80000     && Just count to 80000 before 
	NEXT MyCounter               && cleaning MyText on the form 

So, instead of my code (FOR...NEXT) the Sleep will provide the same amount of time in any computer, which is what I want.

This kernel32 will work in any Windows (32 or 64 bits)?

Thank you,
SitesMasstec

RE: Use of Timer control

>This kernel32 will work in any Windows (32 or 64 bits)?
Yes


In the moment the Windows system will not have a 32bit subsystem, VFP applications themselves won't run.

You still haven't got it, do you? Any software not recompiled as 64bit software still does run, it does so, because Microsoft kept a 32bit subsystem and made a few mechanisms like split system folders, split registry and more.

Bye, Olaf.

RE: Use of Timer control

Don't put the DECLARE in the Cllick event. Although it does no serious harm, it is wasteful of resources. Better to put it at the very start of your program, where you do all your other initialisation.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Use of Timer control

(OP)
Hello colleagues!

Ok, Mike, I followed yor advice and put the DECLARE clause in the main PRG file (which calls the form), thank you.

Olaf, thank you for your clear explanation about 32 bit running on a 64bit machine. Now I got it.

Tamar, I implemented your solution, thanks again. Just a note: if I use SLEEP(1) or SLEEP(5) or SLEEP(10) the result is the same!

Thank you,
SitesMasstec

RE: Use of Timer control

Quote:

if I use SLEEP(1) or SLEEP(5) or SLEEP(10) the result is the same

That shouldn't be the case. But it's possible that the numbers are so small that you don't notice the difference. Remember, those numbers are milliseconds. If you want the text to be visible long enough for the user to see it, you would need to give it at least one second, and possibly more. So SLEEP(1000) would be more appropriate.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Use of Timer control

(OP)

Oh, yes Mike, I understand this. I used SLEEP(3) because the code bellow (using SLEEP(500)) took 100 seconds to show the "phantom" message on the form:

CODE -->

thisform.MyText.Caption="Hello Word!"

FOR Position=200 TO 380 SKIP 10
	thisform.MyText.Top = Position
	thisform.MyText.Visible = .T.

	SLEEP (500)

	thisform.MyText.Visible = .F.
NEXT Position
thisform.MyText.Visible= .F. 

If SLEEP (500) takes 0,5 second...
... the loop 200 TO 380 SKIP 10 (200, 210, 220,... till 380) is equal to 19 times x 0,5 second = (shouLd take) 9,25 seconds, but it took more than a minute and a half (100 seconds)!!

Thank you,
SitesMasstec

RE: Use of Timer control

FOR has STEP, not SKIP.

SKIP was most likely ignored, so you steppd through 181 iterations.

Just tried this, it doesn't error, but it steps with step size 1, just as the default FOR loop does:

CODE

FOR i = 10 TO 100 skip 10
  ? i
ENDFOR 

You want to loop in increment steps of 10:

CODE

FOR i = 10 TO 100 STEP 10
  ? i
ENDFOR 

Bye, Olaf.

RE: Use of Timer control

Do you have a good reason for toggling MyText.Visible each time round the loop, that is, just before and after calling SLEEP()? It seems to me that that would cause an unpleasant flicker. I wonder what the effect would be if you took that out - in other words, only set .Visible to .T. before the start of the loop and then to .F. at the end.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Use of Timer control

Mike, there might be a good reason for that in conjunction with Windows Fonts ClearType technique, making a text invisible might clear itself and all extra ClearType pixels, while simply just moving it might keep some blurred pixels.

Haven't tried, though.

Bye, Olaf.

RE: Use of Timer control

(OP)

One problem I detected is that it is not obeying the SKIP 10. The text is going down stopping each point during 0,5 second (Top=200, Top=201, Top=202... till Top=380)!

Thank you,
SitesMasstec

RE: Use of Timer control

Yes, that should be clear now, because SKIP is the wrong option for a FOR loop, see my answer above.

Bye, Olaf.

RE: Use of Timer control

(OP)

Yes Olaf, I changed the wrong clause SKIP to STEP and now it is ok!

Mike, yes, really MyText.Visible is not needed each time round the loop. I put it before the loop.

Now the problem is solved with your valuable help. Thank you all!

Thank you,
SitesMasstec

RE: Use of Timer control

Yes, that would explain it. The SKIP is ignored - or, rather, it is treated as a comment. This is the case with all (or, at least, most) of this type of construct. It's why you can write something like IF <condition> / <commands> / ENDIF <condition>.

That's why it is taking so long. It is exectuting the loop 180 times rather than 18 times.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Use of Timer control

Exactly, Mike. I tried (see above) and SKIP 10 doesn't error but means the default step size of 1.

Bye, Olaf.

RE: Use of Timer control

The "kindness" of the parser works in your favor some times, such as the days you've been working a lot in VBScript:

CODE -->

If <condition> Then 

Other times, it just hides glaring errors. wink

RE: Use of Timer control

Well, THEN actually IS an optional keyword and not just "kindness".
https://msdn.microsoft.com/en-US/library/w6eteb93(...

In the end, it's planned kindness to accept THEN instead of the usual simple quirk of the compiler to not care about anything following an END keyword.

The parser kindly skipping the SKIP also isn't the usual type of carelessly ignoring anything after the ENDxyz part of VFP code.

Seems the parser only cares for STEP after the upper limit of a for loop, although you can write something like

CODE

additional=3
FOR i = 1 TO 10 + additional
  ? i
ENDFOR 
Where the + additional part makes sense and is also handled correctly. So it's not simply explained by the parser ignoring the rest of the line unless there is a STEP keyword, the parser has to expect any expression as the upper loop limit. So it's yet another quirk of the parser and compiler.

There are a few more, I think every command or part of command having no further extension means the parser simply ignores the rest of the line. You can also write anything after DOEVENTS FORCE

SKIP is tricky in this context, as it's a reserved word and command itself, it's also syntax colored blue (with standard syntax colors), so it also doesn't get apparent, but debugging shows your step increments are just 1.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close