nexurus Posted June 24, 2014 Share Posted June 24, 2014 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! Link to comment Share on other sites More sharing options...
Solution Zedna Posted June 24, 2014 Solution Share Posted June 24, 2014 (edited) Put include statements at top of your script and not inside of function. like this: #include <File.au3> #include <MsgBoxConstants.au3> Func CreateTxt() ... Edited June 24, 2014 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
nexurus Posted June 25, 2014 Author Share Posted June 25, 2014 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 25, 2014 Moderators Share Posted June 25, 2014 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
nexurus Posted June 25, 2014 Author Share Posted June 25, 2014 (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. Edited June 25, 2014 by nexurus Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now