Jump to content
Sign in to follow this  
meatsack

Teach a noob to fish, Where do I put MsgBox to view variables: all of them

Recommended Posts

meatsack

By first giving him the fish, the fish that is used as the bait: Message Box. Can someone write down the code for me that I can cut and paste into my code so that I can see the value of all(or at least one) of the variables in my script. If I had that, then I could use SciTE, run to cursor and see what my script is doing or not doing so I can futz around with the code on my own.

For example: On my monitor I want to see my script in one window and then in a second window I want to see the value of my variable or all my variables. Then I can "run to cursor" the next line or two and see if the value of my variable or variables has changed. Is that possible? The "output" window in SciTE doesn't do that and neither does "AutoIt Debugger." I see that "AutoIt Debugger" has a "variables" window but it displays the number of that particular variable in that window it doesn't tell you what the PC thinks the value is at any given step in your script. I will be eternally grateful. Thank you.

Share this post


Link to post
Share on other sites
Melba23

meatsack,

Does this help: :graduated:

#include <GUIConstantsEx.au3>
 
Global $iCount = 0
 
$hGUI = GUICreate("Test", 500, 500)
 
$hButton = GUICtrlCreateButton("Add", 10, 10, 80, 30)
 
GUISetState()
 
While 1
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $iCount += 1
            MsgBox(0, "Value", "$iCount = " & $iCount)
    EndSwitch
 
WEnd

If not then please explain why not and we will try and get you sorted. I manage to debug quite easily with MsgBox, ConsoleWrite and _ArrayDisplay. ;)

Jos' new Debug addition to AutoIt3Wrapper is also very helpful:

#AutoIt3Wrapper_Run_Debug_Mode=Y
 
#AutoIt3Wrapper_run_debug=Off
 
#include <GUIConstantsEx.au3>
 
$hGUI = GUICreate("Test", 500, 500)
 
$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
 
GUISetState()
 
While 1
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            #AutoIt3Wrapper_run_debug=On
            ConsoleWrite("Button pressed" & @CRLF)
            #AutoIt3Wrapper_run_debug=Off
    EndSwitch
 
WEnd

as it lets you see the code flow in specified parts of your script - you do need his Beta version though. ;)

Over to you. :)

M23

Edit: Added link.

Edited by Melba23

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

 

Share this post


Link to post
Share on other sites
meatsack

Thanks this looks like your sending me in the right direction to enable me to check variable values.

Ok what that did for me was: 1 Opened a window labeled "Test" with a button entitled "Add." 2. When I hit the button it just identifies the value for the variable $iCount in a new pop up window named value. That last window also has a button labeled "ok" and kills the window when pressed.

So Do I change the variable $iCount to the name of the variable in my code that I am interested in? How do I determine where in the script it is when it has given me this value? Also, I just discovered the "Watch" window in "AutoIt Debugger" is that how you check the value of your variable line to line, just using that window plus the run to cursor part of "AutoIt Debugger?"

Edited by meatsack

Share this post


Link to post
Share on other sites
Melba23

meatsack,

Pressing the "OK" button in the MsgBox does not "kill the window" - only the [X] in the main GUI does that. :)

I was trying to show you what you asked:

then in a second window I want to see the value of my variable

All you have to do is add the MsgBox line to your script at the point you wish to determine the value of a variable and put the variable name into the final parameter of the MsgBox call. :graduated:

You can do something similar with ConsoleWrite - except that does not pause the script. ;)

I have never used AutoIt Debugger (nor ever found the need) so I cannot help you with your supplementary questions, sorry. ;)

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

 

Share this post


Link to post
Share on other sites
meatsack

Thank you for that scripting technique. Ok, I was able to play around with that. And I did get it to show me other variables in my code, however I was not able to identify the value of the variable "$output." Is there something I am doing wrong?

#Include <File.au3>
#include <Excel.au3>
#include <Array.au3>
#include <String.au3>
#include <IE.au3>
HotKeySet("^.", "quit")
#include <GUIConstantsEx.au3>

Local $s_FromName = 'my'               ; From Name
Local $s_FromAddress = 'my'         ; From @mail
Local $s_ToAddress = 'a'         ; To @mail
Local $s_Username = 'my'               ; Gmail Username
Local $s_Password = 'm'           ; Gmail Password
Local $oFile = @ScriptDir & "\test1.xls"        ; Excel File
                          ; First time to start!

        gmailSMTP(excelUpdate())

  
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
            MsgBox(0, "Value", "$output = " & $output)

Thanks.

Share this post


Link to post
Share on other sites
BrewManNH

You need to move the MsgBox to a line before the Return $output inside your function.


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

Share this post


Link to post
Share on other sites
meatsack

:graduated: Thank you BrewManNH and Melba23, I am in business now. That enabled me to see my array. BTW what happens to the data in the variable $output after the execution of the return function? I think I can do much better at fishing now. No more of this: ;)

Given the number of views on this threat of over 47 It may be helpful if someone were to put a tutorial or maybe something in the wiki that hey if you want to view variables to help you trouble shoot then try 1. the watch function window of AutoIt Debugging program 2. Cut and paste: MsgBox(0, "Value", "$output = " & $output) wherever you want the program to identify your variable(replace $output with your variable) and it has the added benefit of pausing your program until you shut down the window that has popped up. 3. You could also try _________. :)

Share this post


Link to post
Share on other sites
BrewManNH

After you exit the function, using Return or just having it end, any local variables disappear as if they never existed.

They ONLY exist inside the function, that's what local means when you declare the variable in the function, and cease to exist afterwards.

BTW, if you use the full version of SciTE4AutoIt3 to write your scripts, you can highlight a variable name and hit ALT-D which will create a consolewrite line just after your variable line that will send the contents of the variable to the console in SciTE.

EDIT: Typo

Edited by BrewManNH

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

Share this post


Link to post
Share on other sites
meatsack

Oh, I see. I appreciate your help BrewManNH. Also, all the others who helped me including Syed23, Jos. Thanks I'll try the consolewrite ALT D for fun and see how that goes. Again, thank you for helping me.

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  

×