Jump to content

Script Ending & I Dont Understand Why


jbh5000
 Share

Recommended Posts

Thanks in advance or any help.

I am building a fairly simple (or so I thought) script to handle a few repetitive tasks. I have a loop that I run to listen for Hotkeys and fire functions.

There is one specific function that seems to kill the script at the same place every time but I cannot understand why.

I have posted the script and notated in the comments where the issues is at roughly line 7-8.

I am very green, but seem to have made it work great other than this.

Any help would be appreciated.

Feel free to ask for any additional information needed. I am not quite sure what all you need to provide a complete analysis.

Thanks

Func runinitialdisclosurereport ()          
$i = 0                              ;Set variable i to 0
Do                                  ; Continue to Do
Send ("{Down}")                 ;Push the Down Arrow Key
$i = $i + 1                     ;Increase variable i by 1
Until $i = 52                       ;Repeat this process 52 times or until i=52
Send ("{Enter}")                    ;Press Enter to run report       #### This is where it is faling
Sleep (1000)                        ; Pause 1 Seconds                #### the script exits here Exit Code: 0        


If WinExists("[Class:#32770]") Then     ;check to see if the no records popup box exists
   
   WinClose ("[Class:#32770]")          ;if it exists close it
   Send ("!f")  ;Alt-F                  ;ALT-F Activate the File Menu
    Send ("x")                          ;X for Exit
Else                                    ;If the no records popup box does not exist Continue
If $location = "home" Then              ; If I am working from home set the color variable
    $color=0x0069FF
ElseIf $location="work" Then            ; If I am at work set the color variable
    $color=0x026AFE
EndIf



While PixelGetColor ( 870,032) <> $color        ;If the excel file is not present wait for it
Sleep (1000)
WEnd

Send ("!f")         ;Alt-F to activate file menu
Send ("a")          ;A for Save As
Send ("C:\Documents and Settings\auto\My Documents\Point Report Storage Files\Compliance Disclosure Reports\Files That Need Initial Disclosures.xls") ;directory
Send ("{Enter}")    ;Enter to Save
Send ("y")          ;y to confirm overwrite
EndIf


If $location = "home" Then                      ; If I am working from home set the color variable
    $color=0xEFEBDE                     
ElseIf $location="work" Then                    ; If I am at work set the color variable
    $color=0xECE9D8
EndIf

While PixelGetColor ( 300,150) <> $color        ;Wait for the excel file to close
Sleep (1000)                                    ;Pause 1 Sec
WEnd
Send ("{F2}")                                   ; Press F2 to change screens
deletefirstrowofexcelfile ()                    ;run the function that deletes the first row of excel
EndFunc
Link to comment
Share on other sites

After a little more experimenting it seems to work on fresh runs after a reboot, but if I try to run it a second time it fails and it fails every time after that.

If I reboot and run it works once and then fails from there on out.

Any ideas?

Link to comment
Share on other sites

  • Moderators

jbh5000,

First, please bear in mind that as I have no access to your particular files, these are very much shots in the dark. :D

Looking at the code, there is nothing which should make it exit at that point - normally a script will only end at Exit, on an error or when it runs out of commands to execute. Are you sure that you are, in fact, exiting at the very line of code you indicate? I ask because it looks to me that if the Send("{Enter}") ;Press Enter to run report line fails, there is nothing to stop the code running through the rest of the function without a pause and then perhaps stopping elsewhere.

I have often found that it is worth adding a short Sleep command betwen keystrokes when using Send - try adding a Sleep(250) before your Send("{Enter}") line. Additionally add some ConsoleWrite (or MsgBox) lines around the point where you believe the script to be exiting to try and debug exactly which lines are being executed.

Finally - are you sure that there is absolutely no difference in the behaviour of your app when you try to run the script a second time? Not 51 or 53 Send("{Down}") commands? Often on an initial run there is key that needs to be pressed which becomes redundant on subsequent passes.

Sorry I cannot be of more help. Please let me know if any of the above helps - particularly if the addition of the debugging lines pinpoints an exit point other than the one you have shown in the script.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...