mcintoow Posted December 18, 2013 Share Posted December 18, 2013 (edited) First time post so please let me know if the format is incorrect or I'm posting in the wronf forum.I'm having issue with this script. I'm hoping someone can help me out.The below script works as expected. expandcollapse popupif FileExists ("H:\documents\wordq\*.wdq") then MsgBox (4096, ".WDQ", "Exist") Else ShellExecute ("notepad.exe") endif #Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> #include <Process.au3> $dst = "h:\documents\wordq\" ;specify folder $a_FileList = _FileListToArray2() _ArraySort($a_FileList, 1, 1, $a_FileList[0][0], 1) ShellExecute($a_FileList[1][0]) Func _FileListToArray2($s_Mask='*') $h_Search = FileFindFirstFile($dst & '\' & $s_Mask) $s_FileName = FileFindNextFile($h_Search) If Not @error Then Dim $a_File[100][2] dim $sExt While Not @error $sExt = stringright($s_Filename, 4) if ($sext = ".wdq") then MsgBox(4096, "Extension", $sExt) if StringInStr($s_FileName,'.',0,-1) Then $s_FullName = $dst & '\' & $s_FileName $a_File[0][0] += 1 If $a_File[0][0] >= UBound($a_File) Then ReDim $a_File[$a_File[0][0] * 2][2] EndIf $a_File[$a_File[0][0]][0] = FileGetLongName($s_FullName) $a_File[$a_File[0][0]][1] = FileGetTime($s_FullName,0,1) EndIf EndIf $s_FileName = FileFindNextFile($h_Search) WEnd ReDim $a_File[$a_File[0][0] + 1][2] Return $a_File EndIf EndFuncBut what I really want to do is check if H:documentswordq*.wdq exists and if it does I want to open the newest *.wdq file. If it doesn't open notepad.exe.When I rearrange the if fileexists command like below I receive this error... "C:\Program Files (x86)\AutoIt3\Include\File.au3 (47) : ==> "If" statement has no matching "EndIf" statement.:"expandcollapse popupif FileExists ("H:\documents\wordq\*.wdq") then MsgBox (4096, ".WDQ", "Exist") #Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> #include <Process.au3> $dst = "h:\documents\wordq\" ;specify folder $a_FileList = _FileListToArray2() _ArraySort($a_FileList, 1, 1, $a_FileList[0][0], 1) ShellExecute($a_FileList[1][0]) Func _FileListToArray2($s_Mask='*') $h_Search = FileFindFirstFile($dst & '\' & $s_Mask) $s_FileName = FileFindNextFile($h_Search) If Not @error Then Dim $a_File[100][2] dim $sExt While Not @error $sExt = stringright($s_Filename, 4) if ($sext = ".wdq") then MsgBox(4096, "Extension", $sExt) if StringInStr($s_FileName,'.',0,-1) Then $s_FullName = $dst & '\' & $s_FileName $a_File[0][0] += 1 If $a_File[0][0] >= UBound($a_File) Then ReDim $a_File[$a_File[0][0] * 2][2] EndIf $a_File[$a_File[0][0]][0] = FileGetLongName($s_FullName) $a_File[$a_File[0][0]][1] = FileGetTime($s_FullName,0,1) EndIf EndIf $s_FileName = FileFindNextFile($h_Search) WEnd ReDim $a_File[$a_File[0][0] + 1][2] Return $a_File EndIf EndFunc Else ShellExecute ("notepad.exe") endifThanks to anyone who can offer some advice. Edited December 18, 2013 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 18, 2013 Moderators Share Posted December 18, 2013 mcintoow,Welcome to the AutoIt forum. But please pay attention to where you post - the "Developer Chat" section where you started this thread is not for general support questions. I have moved the thread for you, but would ask you to be more careful in future. And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. 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...
Moderators JLogan3o13 Posted December 18, 2013 Moderators Share Posted December 18, 2013 Look at your last few lines of code. You have an EndFunc, then an Else with no If statement. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
markyrocks Posted December 18, 2013 Share Posted December 18, 2013 (edited) Your if statements are kinda big just use it like this. If <equation> then <command> Endif Short and sweet You have ifs and Endif all over the place Edited December 18, 2013 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
MilesAhead Posted December 18, 2013 Share Posted December 18, 2013 Your if statements are kinda big just use it like this. If <equation> then <command> Endif Short and sweet You have ifs and Endif all over the place +1 it's a good idea to use Tidy as you go along. The indentation makes it obvious when the block starts and ends are unbalanced. My Freeware Page Link to comment Share on other sites More sharing options...
Exit Posted December 18, 2013 Share Posted December 18, 2013 (edited) It is not explicitly written in the help file, but function definitions may not be inside of Do ... until IF ... endif for ... next switch ... Endswitch Select ... Endselect while .. wend with ... Endwith constructs. Edited December 19, 2013 by Exit BrewManNH 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
BrewManNH Posted December 18, 2013 Share Posted December 18, 2013 Very good point Exit. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
markyrocks Posted December 19, 2013 Share Posted December 19, 2013 (edited) ok so i got home looked the op code over.... i'd guess it needs a lil work. i think you should rethink how your using arrays. most arrays we'll say dim $array once its in a loop it looks like this $x = 1 .... $array[$x] once something added to that slot in the array then $x += 1 to move array to next slot. Before that happens tho if its possible to exceed the original array size then you make statement like If $x >= ubound($array) then redim $array[$x + 2] or whatever you see fit for this portion. I made some notes in your code and changed a lil bit. I didn't mess with much because I'm not exactly 100% sure what your trying to accomplish but check it out. Ask more questions study the help fileexpandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIComboBox.au3> #include <Process.au3> if FileExists ("H:\documents\wordq\*.wdq") then MsgBox (4096, ".WDQ", "Exist") Else ShellExecute ("notepad.exe") endif $dst = "h:\documents\wordq\" $a_FileList = _FileListToArray2() ;this is very confusing using a prexisting function name plus a 2...... _ArraySort($a_FileList, 1, 1, $a_FileList[0][0], 1) ShellExecute($a_FileList[1][0]) Func _FileListToArray2($s_Mask='*') ;this is called with no parameter never seen a variable defined like this in a function param $h_Search = FileFindFirstFile($dst & '\' & $s_Mask) $s_FileName = FileFindNextFile($h_Search) Dim $a_File[100][2] dim $sExt While Not @error $sExt = stringright($s_Filename, 4) if ($sext = ".wdq") then MsgBox(4096, "Extension", $sExt) EndIf if StringInStr($s_FileName,'.',0,-1) Then $s_FullName = $dst & '\' & $s_FileName EndIf $a_File[0][0] += 1 ;all this does is add 1 to a_file[0][0] does not make it a_file[1][0] or a_file[0][1] If $a_File[0][0] >= UBound($a_File) Then ;this is kindof an odd statement here as well ReDim $a_File[$a_File[0][0] * 2][2] ;this is a mess EndIf $a_File[$a_File[0][0]][0] = FileGetLongName($s_FullName) ;this is overyly complicated for no reason $a_File[$a_File[0][0]][1] = FileGetTime($s_FullName,0,1) ;same with this $s_FileName = FileFindNextFile($h_Search) WEnd ReDim $a_File[$a_File[0][0] + 1][2] ;how many times you gona redim this? Return $a_File ;wheres it returning to? EndFunc Edited December 19, 2013 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
jchd Posted December 19, 2013 Share Posted December 19, 2013 (edited) It is not explicitly written in the help file, but function definitions may not be inside of Do ... until IF ... endif for ... next switch ... Endswitch Select ... Endselect while .. wend with ... Endwith constructs. True for all but With ... EndWith which are not true block construct last time I checked. They behave like individual instructions except of course that EndWith must have been preceeded by some With. EDIT: the reality is always more subtle. Edited December 19, 2013 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Exit Posted December 19, 2013 Share Posted December 19, 2013 True for all but With ... EndWith which are not block construct last time I checked. They behave like individual instructions except of course that EndWith must have been preceeded by some With. Real sorry to disagree. Just try this little snippets. #include <IE.au3> $oIE = _IECreate() With $oIE ConsoleWrite("Browser name is " & .name & @LF) ConsoleWrite("Browser locationname is " & .locationname & @LF) EndWith _IEQuit($oIE)#include <IE.au3> $oIE = _IECreate() With $oIE ConsoleWrite("Browser name is " & .name & @LF) Func _MyFunc() EndFunc ;==>_MyFunc ConsoleWrite("Browser locationname is " & .locationname & @LF) EndWith _IEQuit($oIE) App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
jchd Posted December 19, 2013 Share Posted December 19, 2013 I stand corrected. It used to work that way but changed in the meantime. Note that only Au3Check barks at your second example, which otherwise behaves just like the first when run. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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