Sign in to follow this  
Followers 0
nexurus

Compile error on include files

5 posts in this topic

Hey guys, new to AutoIt (I know, seems like everybody says that when they ask a question) and I'm having an issue that is strange to me.

Forgive me for using the wrong terms here, still learning.

In my script, I have included File.au3 which is dependent on Array.au3. When I compile, it give me an error on Array.au3 saying:

error: syntax error

warning; $vValue: possibly used before declaration.

error: $vValue: undeclared global variable

error: _ArrayAdd(): undefined function

I get this on all functions in Array.au3. This is the file that came with AutoIT and I have no made any changes. What am I doing wrong?

Here is my function. It's simply receiving user inputs and trying to write to a text file. Not sure what did wrong:

Func CreateTxt()
    #include <File.au3>
    #include <MsgBoxConstants.au3>

    Local $sFilePath = $rDir&"\"&$uInput&".txt"
    
     If Not _FileCreate($sFilePath) Then
        MsgBox(0, "", "An error occurred whilst writing the temporary file.")
    EndIf

    Local $hFileOpen = FileOpen($sFilePath)
    If $hFileOpen = -1 Then
        MsgBox(0,"","An error occured when reading the file.")
    EndIf

    FileWrite($hFileOpen,"@Echo Off" & @CRLF)
    FileWrite($hFileOpen,"Joined "&gGroup&" on this date: "&gDate)

    FileClose($hFileOpen)

    MsgBox(0, "", "Contents of the file:" & @CRLF & FileRead($sFilePath))
EndFunc

Here's the first section in Array.au3 that is giving the error. I know the rest do the same because I commented out this function and it gave the same errors on the next function. I have since returned the file it's original state from a backup.

; #FUNCTION# ====================================================================================================================
; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
; Modified.......: Ultima - code cleanup
; ===============================================================================================================================
Func _ArrayAdd(ByRef $avArray, $vValue)
    If Not IsArray($avArray) Then Return SetError(1, 0, -1)
    If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, -1)

    Local $iUBound = UBound($avArray)
    ReDim $avArray[$iUBound + 1]
    $avArray[$iUBound] = $vValue
    Return $iUBound
EndFunc   ;==>_ArrayAdd

Any help would be really appreciated here!

Share this post


Link to post
Share on other sites



Hey! That worked! Why did that made a difference? I didn't realize there was a difference in how it functions depending on where the include statements are located.

Share this post


Link to post
Share on other sites

nexurus,

An #include line adds the code of the file into your script at the point at which you have the directive. AutoIt is pretty forgiving, but placing them inside functions is a recipe for disaster for several reasons - including:

 

- Variables must be declared before use, so any declared by the #include might be declared too late.

- Placing an #include inside a function could well lead to functions being declared inside other functions, which is a fatal error.

So it is usually best to place the #include lines at the top of the script - all I ever place before them are any necessary compile directives. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

#5 ·  Posted (edited)

Thank you both for the resolution and explanation. Now to figure out why the rest of the it is not working! Thanks again, I'm sure you'll see more questions from me.  :thumbsup:

Edited by nexurus

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  
Followers 0