Jump to content

Script ends early


Guest
 Share

Recommended Posts

Hi all, my scripts have been working for the past year or two, but after some updates (windows/autoit) one of my scripts just seems to end before it actually does any work. I searched around and have tried a few things but nothing has helped.

I tried the tray debug and it didn't show anything. The script ends with exit code 0. I tried some error checks, but they didn't report anything.

Basically my script reads from my excel file, stores every cell in a variable, and then starts calling functions. Excel opens fine, but after about 10 seconds the script just exits. Any help is appreciated.

 

Link to comment
Share on other sites

#include <Excel.au3>
#include <MsgBoxConstants.au3>

HotKeySet ("{ESC}", "Stop")
Global $1Excel = _Excel_Open()
Global $1Workbook = "\\x\Clinic-New.xlsx"
Global $2Workbook = _Excel_BookOpen($1Excel, $1Workbook)

Global $ResultCM = _Excel_RangeRead($2Workbook, Default, "A2") ;ParentCM
Global $ResultStartDate = _Excel_RangeRead($2Workbook, Default, "C2") ;Onboarding Start Date

 

Link to comment
Share on other sites

  • Moderators

@Xeiruz Welcome to the forum. Your script has 0 error checking. You need to check for an error at each line, so you know where it is failing. Look in the help file for each of those Excel functions; the given example includes error checking.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Ok, I've added it to every step and nothing it popping up, it simply ends the script.

 

#include <Excel.au3>
#include <MsgBoxConstants.au3>

HotKeySet ("{ESC}", "Stop")
Global $1Excel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Global $1Workbook = "\\x\x\Clinic-New.xlsx"
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error connecting to spreadsheet on network." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Global $2Workbook = _Excel_BookOpen($1Excel, $1Workbook)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error opening excel workbook2." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Global $ResultCM = _Excel_RangeRead($2Workbook, Default, "A2") ;ParentCM
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error reading A2." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 

Link to comment
Share on other sites

When I extract the code with no functions and run it all at once, it seems to work, but once it's in the larger script it times out after reading excel.

This is the func in the main script

Func ParentCM()
Sleep (5000)
WinActivate ("CA Service")
Sleep (1000)
ControlClick ("CA Service Desk Manager", "", "Internet Explorer_Server1", "left", 2, 850, 35)

This is what I actually run

#include <Global.au3>

Call ("ParentCM")

 

Link to comment
Share on other sites

So I keep messing with it and it really seems like it's not able to call the func, but it never gives an error??

I'm at a loss, how do you error check a function call other than just putting it in/after the function?

 

#include <Global.au3>
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error reading global file." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Call ("ParentCM")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error calling func." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 

Link to comment
Share on other sites

Instead of "call", why not just

ParentCM()

?

Anyway, that code doesn't mean the function is not being called, i mean, it jumps to the function and only executes the next line, after it leaves the function, so put checks inside the function, because if there's a problem that crashes it, it will never get to the msgbox.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

@careca yeah I figured the error check after wouldn't help. I didn't realize you didn't need "call", so that's removed, no change though.

I had an error check as the first like in the func itself, but also added it to the first few rows, and it never gets anywhere. It doesn't focus the window or anything.

It still just ends after about 10 seconds. It opens the excel file, but nothing else.

#include <Global.au3>
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error reading global file." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
ParentCM()
Func ParentCM()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error running ParentCM." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Sleep (5000)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error running ParentCM." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
WinActivate ("CA Service")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error running ParentCM." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Sleep (1000)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error running ParentCM." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
ControlClick ("CA Service Desk Manager", "", "Internet Explorer_Server1", "left", 2, 850, 35)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error running ParentCM." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
EndFunc

 

Link to comment
Share on other sites

What about this?

Func ParentCM()
$WW = WinWait("CA Service", '', 5)
If $WW <> 0 Then
$WA = WinActivate ("CA Service")
If $WA <> 0 Then
Sleep (1000)
ControlClick ("CA Service Desk Manager", "", "Internet Explorer_Server1", "left", 2, 850, 35)
Else
MsgBox(64, 'Fail', 'Did not activate window')
exit
EndIf
Else
MsgBox(64, 'Fail', 'Did not detect window')
exit
EndIf
EndFunc

The problem with

If @error Then Exit MsgBox($MB_SYSTEMMODAL, @ScriptName, "Error running ParentCM." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Is that, from my understanding, you exit, and then call the msgbox, well, if you exit, how is the box supposed to appear? Or am i thinking wrong about this?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Well that exit/msg is how it's displayed in the help file example, so I don't think that's an issue.

I tried with yours and it doesn't do anything either. Honestly, it seems like it's killing the script before it makes it to the function call.

It opens the excel, but nothing after that.

Link to comment
Share on other sites

  • Moderators
8 minutes ago, careca said:

Or am i thinking wrong about this?

You are :)

Exit MsgBox(0, "", "OMG an exit error!")

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Would it be possible to post a runnable script so that we can see what you're doing? These bits and pieces are doing nothing to help anyone in figuring out what's going wrong. Not to mention, your last post with code makes no sense whatsoever. None of that s even remotely close to what you're saying is happening, mainly because there's no Excel functions in it, and you're using ControlClick to click on something but we have no idea what that something is.

Make sure the script you post is complete, not a tiny portion of it that doesn't do anything that you say isn't working. Also, a sample of any files that you're accessing would be helpful as well.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Yeah sorry for the confusion.
I haven't had to ask for help before so I wasn't really sure how to present the info to someone other than myself.

You asking for the full script (about 1k lines) helped!
I found an unclosed function on the veeery last line, that wasn't throwing an error because it wasn't being called.

Took about 5 hours to find that and I feel real dumb.
Thanks for making me dig through the code!

Link to comment
Share on other sites

36 minutes ago, Xeiruz said:

I found an unclosed function on the veeery last line, that wasn't throwing an error because it wasn't being called.

? SciTe tells me right away if there's a problem like that. Yours didn't? How weird

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

1 hour ago, Xeiruz said:

I found an unclosed function on the veeery last line, that wasn't throwing an error because it wasn't being called.

You should run Au3Check on all of your scripts, and that would make it easier to find these types of issues. 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers
9 hours ago, BrewManNH said:

You should run Au3Check on all of your scripts, and that would make it easier to find these types of issues. 

...which is automatically  done when you install the separate full version of SciTE4AutoIt3.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What makes me wonder, is there a reason why the full version is not installed/included in AutoIt?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Developers

As it is considered not as a core item and people should be able to choose their editor of choice.

I solely maintain the SciTE4AutoIt installer and only the SciTE source is part of the shared SVN, all other sources of the compiled programs (tidy,au3stripper) aren't shared.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Though I've been using Autoit for years, I still don't know a lot.
I didn't even realize there was a more in-depth editor. I'll definitely be installing that today.

Thanks for being so helpful guys.

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...