kangkong
11-14-2000, 03:36 AM
pls review this code of mine which i used for a cognos script
editor(macro) ,it uses visual basic code anyway
This script autoexe on a scheduled time and then opens outlook ,runs
it,waits for 2 seconds,checks if its fully loaded and proceed the rest
of
the task...
the person who did this script first uses for loop to delay,thus u will
see some for loop being remarked.
now,i did some research and introduced sleep and functions like
openprocess,getexitprocess,closehandle and isActive fr some source
code...problem is, i cannot reli understand the task of open process
and
getExitCodeProcess, and wat exactly does IsActive(taskID) returns?
therefore in this segment
"do until IsActive(TaskID) <> 0
sleep(2000)
loop "
wat i did is try and check if the process is finally loaded,else i
would
delay for 2 seconds...problem is,i do not noe wats goin on in isActive
function;What does it really returns?Please help me and reply asap!
I am an attachment working in a company..
thanks in advance!
' this is a macro
'declarations similiar to win32API,do not change!!!
Declare Sub Sleep Lib "Kernel32" Alias "Sleep"(ByVal dwMilliseconds As
Long)
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As
Long,ByVal bInheritHandle As Long ,ByVal dwProcessId as Long) as Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As
Long, IpExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As
Long
Function isActive(hprog As Long) As Long
Dim hproc As Long, RetVal As Long
Const PROCESS_QUERY_INFORMATION = 0
CONST STILL_ACTIVE = 259
hProc = OpenProcess(PROCESS_QUERY_INfORMATION, FALSE, hprog)
if hProc <> 0 Then
GetExitCodeProcess hProc,RetVal
End If
IsActive = (RetVal = STILL_ACTIVE)
CloseHandle hProc
End Function
'the end
Sub Main
Dim TaskID as Integer
TaskID = shell("C:Program FilesMicrosoft OfficeOfficeOUTLOOK.EXE")
appactivate "Microsoft Outlook"
'Sleep(2000)
do until IsActive(TaskID) <> true
sleep(2000)
loop
'for x = 1 to 500000
'next
'This will simulate the key pressing sequence Alt F , W, M
'This is the sequence of commands to open the New message box in
Outlook
Sendkeys "%fwm"
'for x = 1 to 200000
'next
Sleep(1000)
sendkeys "{(}DL{)}xxx-xxx" 'This sends the mail id to the to address
box
Sendkeys "{TAB}{TAB}" ' This moves your cursor to the Subject
of
the mail
Sendkeys "TMS PowerCubes Update"
Sendkeys "{TAB}" ' This moves your cursor to the text of
the
mail
Sendkeys " Dear Colleagues,{ENTER}",-1
Sendkeys "{ENTER}",1
Sendkeys " This is a computer generated mail. If you do not recevied
this
mail 1st day of each week , please inform xx."
Sendkeys "{ENTER}",1
'Attached TMS(Bonus) PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
Sleep(1000)
'for x = 1 to 200000
'next
Sendkeys "t:xxx{(}bonus{)}.mdc{enter}", -1 'File name with path
'Attached TMS PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
'for x = 1 to 200000
'next
Sleep(1000)
Sendkeys "t:xxx.xxx{enter}", -1 'File name with path
'Attached NTS(xxx) PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
'for x = 1 to 200000
'next
Sleep(1000)
Sendkeys "t:xxx{(}bonus{)}.mdc{enter}", -1 'File name with path
'Attached NTS PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
'for x = 1 to 200000
'next
Sleep(1000)
Sendkeys "t:xxx.mdc{enter}", -1 'File name with path
SendKeys "%S", 1
End Sub
Lastly,is there a better way to check if a window is fully opened?
thanks again!
ps>theres a time lapse between opening a program or window and being fully loaded
editor(macro) ,it uses visual basic code anyway
This script autoexe on a scheduled time and then opens outlook ,runs
it,waits for 2 seconds,checks if its fully loaded and proceed the rest
of
the task...
the person who did this script first uses for loop to delay,thus u will
see some for loop being remarked.
now,i did some research and introduced sleep and functions like
openprocess,getexitprocess,closehandle and isActive fr some source
code...problem is, i cannot reli understand the task of open process
and
getExitCodeProcess, and wat exactly does IsActive(taskID) returns?
therefore in this segment
"do until IsActive(TaskID) <> 0
sleep(2000)
loop "
wat i did is try and check if the process is finally loaded,else i
would
delay for 2 seconds...problem is,i do not noe wats goin on in isActive
function;What does it really returns?Please help me and reply asap!
I am an attachment working in a company..
thanks in advance!
' this is a macro
'declarations similiar to win32API,do not change!!!
Declare Sub Sleep Lib "Kernel32" Alias "Sleep"(ByVal dwMilliseconds As
Long)
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As
Long,ByVal bInheritHandle As Long ,ByVal dwProcessId as Long) as Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As
Long, IpExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As
Long
Function isActive(hprog As Long) As Long
Dim hproc As Long, RetVal As Long
Const PROCESS_QUERY_INFORMATION = 0
CONST STILL_ACTIVE = 259
hProc = OpenProcess(PROCESS_QUERY_INfORMATION, FALSE, hprog)
if hProc <> 0 Then
GetExitCodeProcess hProc,RetVal
End If
IsActive = (RetVal = STILL_ACTIVE)
CloseHandle hProc
End Function
'the end
Sub Main
Dim TaskID as Integer
TaskID = shell("C:Program FilesMicrosoft OfficeOfficeOUTLOOK.EXE")
appactivate "Microsoft Outlook"
'Sleep(2000)
do until IsActive(TaskID) <> true
sleep(2000)
loop
'for x = 1 to 500000
'next
'This will simulate the key pressing sequence Alt F , W, M
'This is the sequence of commands to open the New message box in
Outlook
Sendkeys "%fwm"
'for x = 1 to 200000
'next
Sleep(1000)
sendkeys "{(}DL{)}xxx-xxx" 'This sends the mail id to the to address
box
Sendkeys "{TAB}{TAB}" ' This moves your cursor to the Subject
of
the mail
Sendkeys "TMS PowerCubes Update"
Sendkeys "{TAB}" ' This moves your cursor to the text of
the
Sendkeys " Dear Colleagues,{ENTER}",-1
Sendkeys "{ENTER}",1
Sendkeys " This is a computer generated mail. If you do not recevied
this
mail 1st day of each week , please inform xx."
Sendkeys "{ENTER}",1
'Attached TMS(Bonus) PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
Sleep(1000)
'for x = 1 to 200000
'next
Sendkeys "t:xxx{(}bonus{)}.mdc{enter}", -1 'File name with path
'Attached TMS PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
'for x = 1 to 200000
'next
Sleep(1000)
Sendkeys "t:xxx.xxx{enter}", -1 'File name with path
'Attached NTS(xxx) PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
'for x = 1 to 200000
'next
Sleep(1000)
Sendkeys "t:xxx{(}bonus{)}.mdc{enter}", -1 'File name with path
'Attached NTS PowerCube'
Sendkeys "%if" ' Alt I , F to insert a new file in
the mail
'for x = 1 to 200000
'next
Sleep(1000)
Sendkeys "t:xxx.mdc{enter}", -1 'File name with path
SendKeys "%S", 1
End Sub
Lastly,is there a better way to check if a window is fully opened?
thanks again!
ps>theres a time lapse between opening a program or window and being fully loaded