Jump to content

AutoIt 1-2-3 Lesson Script Error


 Share

Recommended Posts

Total Newbie to scripting. Doing AutoIt 1-2-3 lessons. Section 3 Controlling & Communicating with IE. 16 Tutorial Files. File 01--Search-Forum. When clicking 'Show Me This" Line 16 gets AutoIt Error:

CODE

3 include <GuiConstants.au3>

4 include <file.au3>

5

6 ; create the GUI.

7 $win = GUICreate("File List/View Demo", 614, 370)

8 ; set the font for the GUI

9 GUISetFont(9, 400, -1, "MS Sans Serif")

10 ; create buttons.

11 $btnList = GUICtrlCreateButton("&List Files", 10, 330, 75, 25)

12 $btnView = GUICtrlCreateButton("&View File", 85, 330, 75, 25)

13 ; create the left list.

14 $TutorItList = GUICtrlCreateList("", 10, 10, 150, 330)

15 create the right edit.

16 $TutorItEdit = GUICtrlCreateEdit("Please select a tutorial from the list to your left." , 175, 10, 420, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL

AutoIt Error box pops up with the following:

Line 16 (File "C:\Program Files\AutoIt3\Lessons\Lessons\Lesson-6.au3")

$TutorItEdit = GUICtrlCreateEdit("Please select a tutorial from the list to your left.", 175, 10, 420, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL

$TutorItEdit = GUICrtlCreateEdit("Please select a tutorial from the list to your left.", 174, 10, 420, 345, ^ERROR

Error Variable used without being declared.

For the other 15 tutorial files when displaying 'Show Me This' script the lesson continually brings up File 01 ONLY with the error so you can't learn the other 15 tutorials. Can someone please help?

Link to comment
Share on other sites

Autoit has advanced and made some changes since that was written, it does need updated. However you will find many scripts throughout the forums that are in need of updating also.

The "main" difference is the #Include you see at the top of the script.

Here is the update for the one you posted

; includes
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>

; create the GUI.
$win = GUICreate("File List/View Demo", 614, 370)
; set the font for the GUI
GUISetFont(9, 400, -1, "MS Sans Serif")
; create buttons.
$btnList = GUICtrlCreateButton("&List Files", 10, 330, 75, 25)
$btnView = GUICtrlCreateButton("&View File", 85, 330, 75, 25)
; create the left list.
$TutorItList = GUICtrlCreateList("", 10, 10, 150, 330)
; create the right edit.
$TutorItEdit = GUICtrlCreateEdit("Please select a tutorial from the list to your left.", 175, 10, 420, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL)
; set the edit colors.
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetColor(-1, 0x000000)
; set focus to the edit.
GUICtrlSetState($TutorItList, $GUI_FOCUS)
; show the GUI.
GUISetState()

; start the loop.
While 1
    ; listen for a message
    $msg = GUIGetMsg()
    ; using select/case for the message
    Select
        Case $msg = $GUI_EVENT_CLOSE 
            Exit
        Case $msg = $btnList
            Set_tutor()
        Case $msg = $btnView
            View_tutor()
    ; end the selections        
    EndSelect
    
WEnd

; Function to populate the left list.
Func Set_tutor()
    $TutList = _FileListToArray (@HomeDrive & "\", "*.txt", 1) ; list files to an array.
    If (Not IsArray($TutList)) Or (@error = 1) Then
        MsgBox(262208, "Tutor Error", "No Files\Folders Found.   ", 5)
        Return
    EndIf
    GUICtrlSetData($TutorItList, "") ; set list to empty.
    For $x = 1 To $TutList[0] ; for loop to place the files in the list.
        GUICtrlSetData($TutorItList, (StringTrimRight($TutList[$x], 4)) & "|", 1) ; string trim the last 4 characters ( .txt )
    Next
EndFunc   

; Function to populate the right edit.
Func View_tutor()
    $s_text = GUICtrlRead($TutorItList) ; read the selected file to a variable.
    If $s_text = "" Then Return
    $s_text = @HomeDrive & "\" & $s_text & ".txt" ; set the location of the file.
    Dim $Tut_text
    If Not _FileReadToArray($s_text, $Tut_text) Then ; read the file to an array.
        MsgBox(4096, "Tutor Error", " Error reading log to Array     error:" & @error)
        Return
    EndIf
    GUICtrlSetData($TutorItEdit, "") ; set the edit to empty.
    For $x = 1 To $Tut_text[0] ; for loop to place the read file into the edit.
        GUICtrlSetData($TutorItEdit, $Tut_text[$x] & @CRLF, 1)
    Next
EndFunc   

; Note
; file read to array, reads the file
; file list to array, lists the files

BTW... Welcome to the Autoit Forums!! ^_^

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Thank you so much. If someone gets a chance someone might want to update the other 15 'Show Me This' tutorials since they all bring up the same one which is for File 01-Search-Forum instead of their own. Have a Spectacular Day!

Link to comment
Share on other sites

Thank you so much. If someone gets a chance someone might want to update the other 15 'Show Me This' tutorials since they all bring up the same one which is for File 01-Search-Forum instead of their own. Have a Spectacular Day!

That be me... lol

I am the Guy responsible ( or not ) just a little lazy... ^_^

You Have a Spectacular Day Too!

8)

NEWHeader1.png

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