CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 1999
    Posts
    8

    is there a delay funtion?

    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


  2. #2
    Join Date
    Jul 1999
    Posts
    145

    Re: is there a delay funtion?

    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!




  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: is there a delay funtion?

    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)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured