Hello, I'm trying to write a simple little TAsk Schedulaer app

When my lable caption timer hits a certian time It's supposed to load a program

If lblTime.Caption = "9:11:25 AM" Then
fullpath = "C:\windows\notepad.exe"
iTask = Shell(fullpath, vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
'ret = WaitForSingleObject(pHandle, INFINITE)
'ret = CloseHandle(pHandle)
End If


However this opens 6 instances of notepad! and i only want it to open one... I'm not really sure what those last two things:waitforsingleobject, and closehandle do so i just commented them out.

Please help i'll be in the IRC if someone needs more info.

Thanks

-edit: Perhaps it has something to do with timer interval?

as per this post I set my timer interval to 1000
http://www.daniweb.com/techtalkforums/thread38847.html

and it looks like it's only loading one instance, however this seems too simple of a fix, if anyone could explain those two functions or a better way to do it, it will be apprciated.

dim flag as Boolean

Private Sub Form_Load()
   ' set flag to false when app starts
   ' I think it defaults to false. Just in case.
   flag = False
End Sub



' Your code.....

If lblTime.Caption = "9:11:25 AM" and Flag = False Then
   flag = True
   fullpath = "C:\windows\notepad.exe"
   iTask = Shell(fullpath, vbNormalFocus) 
   pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
   'ret = WaitForSingleObject(pHandle, INFINITE)
   'ret = CloseHandle(pHandle)
End If

If lblTime.Caption = "9:11:30 AM" then
   ' reset flag for next day
   flag = False
endif

code looks solid i'm sure it will work!

btw do you have any idewa what the
'ret = WaitForSingleObject(pHandle, INFINITE)
'ret = CloseHandle(pHandle)
arre for?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.