Click to See Complete Forum and Search --> : is there a delay funtion?


Sir Static
July 16th, 1999, 02:06 PM
Is there any way to set a delay in VB? I have searched through the help index and havent found anything close to it...

What i am trying to do is make a program that prints out some text in notepad by the use of the 'SendKeys' function but it prints the characters out as fast as the processor can, but this it too fast for the effect i want... I tryed to put it in a timer (using a static int with a case statement so it would print one char at a time) but it would print out anything.


ReturnValue = Shell("notepad.EXE", 1) ' Run Notepad.
AppActivate ReturnValue ' Activate Notepad.
SendKeys "Hello, this is only a test... ~", true



Also i was wondering if buy using the SendKeys function if there is a way to have it use 3 keys at once (eg. control & alt & delete). If not, is there another way to restart the computer?

If you have never used the sendkeys function before i sugest u take my code and through it in a function. It's realy neet

Mikesc
July 17th, 1999, 11:24 AM
Try this:

Command1_Click()
ReturnValue = Shell("notepad.EXE", 1) '
AppActivate ReturnValue,false ' Activate Notepad.

Timer1.Interval = 100
End Sub

Timer1_Timer()
Dim a as string
static i as Long
a="This is a Test"
If i>len(a) then
Timer1.Interval=0
i=0
Exit Sub
End if
If i=0 then i=1
SendKeys mid$(a,i,1),true
i=i+1
End Sub



Of course, here you need a command button and a timer control on your form. If it doesn't work the first time stop and run it again. I had some problems with it not setting focus to the Notepad window which caused it not to print at times. Why I don't know. I've never used the Shell or Appactivate functions. To shut down the computer you have to use API calls. And the API functions you need are different for Windows 9x and for NT. I don't remember them off the top of my head but you can find them at vbaccelerator.com or possibly at PlanetSourceCode. Good luck!

Lothar Haensler
July 19th, 1999, 01:40 AM
for better sleep: use the Sleep API (get the declaration from the API Viewer Add-in)
for rebooting the PC: use ExitWindowsEx API (not so easy in NT)