Jump to content

"If" statement has no matching "EndIf" statement.:


mcintoow
 Share

Recommended Posts

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.

 

if 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
EndFunc
But 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.:"

if 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")
endif

Thanks to anyone who can offer some advice.

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

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

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

 

Link to comment
Share on other sites

  • Moderators

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

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 by Exit

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 file

#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 by markyrocks
Link to comment
Share on other sites

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 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 here
RegExp tutorial: enough to get started
PCRE 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

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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