Jump to content
Sign in to follow this  
meatsack

How to Debug script, Help

Recommended Posts

meatsack

I am not being sucessful at debugging my script. I imagine the best practices debugging steps are something like: 1. Review code for typos. 2. Run code by selecting F5 while in SciTE4. 3. Syntax check the code using CTRL+F5 SyntaxCheck Prod 4. Try running Au3Record then compare your code to what the macro documents to brainstorm some possible directions to go in when modifying your code. 5. ? 6. Post to the General Help and Support thread of the Forum.

I am using SciTE to attempt debugging. I just can't figure out how to debug step by step like you can in VB. I assum you can debug step by step using SciTE. When I pasted

Opt("TrayIconDebug", 1) into my code it doesn't result an any different output in the "output" window. Can anyone tell me if it is just sitting their in the Sleep mode? Should I reduce the Sleep(5000) to something smaller like Sleep(10) or change the timer somhow $vTIme =17 to $vTIme =1? I have read through the tutorials FAQ's, Tutorials, wiki and all the linked resources cited from autoitscript.com What I am trying to do is run my script line 1, then line 2, etc to see where it hangs or seems to have a problem. All it does now is send a blank email. Of course I have deleted my personal info from the sample script below. Any help would be appreciated.

I read where there are a couple of step-by-step debuggers in the Examples section, but the message said: "I believe that they do not work well with Vista/Win 7 because of UAC. If you have the full version of SciTE4AutoIt3, there are a number of debugging tools available to you there as well (automatic insertion/deletion of trace lines, ConsoleWrite, MsgBox commands, etc)."

#Include <File.au3>
#include <Excel.au3>
#include <Array.au3>
#include <String.au3>
#include <IE.au3>HotKeySet("^.", "quit")
Opt("TrayIconDebug", 1)
Local $s_FromName = 'mya'             ; From Name
Local $s_FromAddress = 'mya'            ; From @mail
Local $s_ToAddress = ''   ; To @mail
Local $s_Username = 'mya'             ; Gmail Username
Local $s_Password = ''          ; Gmail Password
Local $oFile = @ScriptDir & "\testz.xls"        ; Excel File
Local $vTime = 10                             ; First time to start!
While 1
    Sleep(5000)
    If @HOUR = $vTime Then
        gmailSMTP(excelUpdate())
        $vTime = 17
    EndIf
    If @HOUR = $vTime Then
        gmailSMTP(excelUpdate())
        $vTime = 10
    EndIf
WEnd
Func excelUpdate()
    Local $Excel = ObjCreate("Excel.Application")   $Excel.Visible = True
    $Excel.WorkBooks.Open($oFile, 2, False)
    $Excel.ActiveCell.QueryTable.Refresh
    $Excel.ActiveWorkBook.Saved = 1
    $Excel.Quit
    $oExcel = _ExcelBookOpen($oFile)
    $oRead = _ExcelReadSheetToArray($oExcel, 2, 1, 40)
    _ExcelBookClose($oExcel)    $output = ""
    For $r = 0 to UBound($oRead,1) - 1
        $output = $output & @CRLF
        For $c = 0 to UBound($oRead,2) - 1
            $output = $output & $oRead[$r][$c] & " "
        Next
    Next
    Return $output
EndFunc
Func gmailSMTP($vBody)
    ; SMTP part [ Without Web-based GUI ]   Local $s_SmtpServer = 'smtp.gmail.com'
    Local $s_IPPort = 465
    Local $s_Subject = 'Calender'
    Local $s_Body = $vBody
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = $s_FromAddress
    $objEmail.To = $s_ToAddress
    $objEmail.Subject = $s_Subject
    $objEmail.TextBody = $s_Body    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $s_IPPort
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    $objEmail.Configuration.Fields.Update
    $objEmail.Send
    If @error Then
        MsgBox(32, "Error", "Error while sending")
        Exit
    EndIf
    $objEmail=""
    $output=""
EndFunc
Func quit()
    Exit
EndFunc

Current error messages: None? or

myAutoItfolderpath /ErrorStdOut my file path and name

Edited by meatsack

Share this post


Link to post
Share on other sites
Syed23

Have you get a chance to look at this Graphical Debugger tool. To me this is really nice tool... you can give a try at this


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
meatsack

<p> </p>

<div>Thanks I had not seen AutoIt Debugger as its not included in the standard download package here. However, I still have a problem. After using AutoIt Debugger</div>

<div>Current error messages: The debug file could not be created (The path is not of a legal form.).</div>

<div> </div> After a syntax check: WARNING: $output: possibly used before declaration. gmailSMTP( $output)

Edited by meatsack

Share this post


Link to post
Share on other sites
Syed23

div> </div> After a syntax check: WARNING: $output: possibly used before declaration. gmailSMTP( $output)

This gives some clue. Declare the variables and give a try. The variable $output did not declared so declare it. also declare the $objmail variable or else you may get the error message to that next time :graduated:


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
meatsack

Done

Local $output = "" ; var declared

Local $ojbmail = "" ; var declared

Current error messages: The debug file could not be created (The path is not of a legal form.).

Also AutoIt Debugger generated the folloiwng error on XPSP3 "An unhandled error was generated. . . . " It seems a little unstable on my OS celeron 2.6 with 1 Gig ram. It opened slow, has crashed more than 3 times and seems to lock up when I try and select the disk icon, multidisk icon, or the icon to the right of those. I think I was able to change the file associations from blank to the correct location of SciTE before the problems with the icons set in. None of my attempts to run the script after these changes or using Autoit Debugger resulted in a sent email.

Share this post


Link to post
Share on other sites
Syed23

For me the script started working fine in both SciTE and Autoit Debugger. Previously i was getting error message on variable "$s_SmtpServer" so i removed it added my SMSTP server name and the script started working fine...


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
meatsack

Now I am at line 20 Sleep(5), I lowered the "Sleep" number to see if it was just waiting was the problem. Still no results. I changed to the yahoo Smtp server. Could you clarify your change. Did you change the name of the variable "$s_SmtpServer" or did you just do away with that variable and wrote the actual name of your Smtp server? Thanks again for replying.

Share this post


Link to post
Share on other sites
Syed23

$objEmail.Configuration.Fields.Item ("[url="http://schemas.microsoft.com/cdo/configuration/smtpserver"]http://schemas.microsoft.com/cdo/configuration/smtpserver[/url]") = $s_SmtpServer ;<====== here i removed the variable name and added  my SMTP server IP ADdress.

instead of the variable give your SMTP server IP address it will work :graduated: i use to do like that

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
Syed23

Ok try like this and sorry for the delay.

$objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

$objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _

"http://smtp.gmail.com" ; <--------------------------------------------------- CONFIGURE YOUR SMPT SERVER CORRECTLY!

$objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
meatsack

Do you mean my code should look like this:

$objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"http://smtp.gmail.com"
$objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

That's not working either. Does AutoIt only work with certain versions of IE and Excel? I have IE 8.0.6 and Excel 2003 SP3 Basic Edition. With my original version it was sending blank emails now it won't even send emails.

Share this post


Link to post
Share on other sites
meatsack

Gmail doesn't work with the standard SMTP port 25.

Look at _InetSmtpEmailCom() function in Examples for a working version.

Jos

Yes, thanks I had it working with port 465 but I will do any modifications suggested on the forum. 1 Question do peek at the value of my variable after a particular line of code has executed do I have to put the code below at the beginning or between each line of code. Do I have to name each variable of which I want to check the value?

Func dbg($msg)
  DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)
EndFunc
 
dbg("The value of Variable 1 at this time is " & $var1)

Or is there a way to look at the value at a specific moment in time with SciTE or "AutoIt Debugging" program? I worry that forum readers will be stupider after having read my questions and comments. I am beginning to think something is not working right such as "AutoIt Debugging" crashing and the icons locking up. I had this working right about 2 months ago, now I can't figure out what changed.

Edited by meatsack

Share this post


Link to post
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
Sign in to follow this  

×