Sign in to follow this  
Followers 0
enigmaforceiv

Having problems with If/Then Statements...

13 posts in this topic

If $BEvent = 1 Then
Func Buyers()
Opt("GUICoordMode", 3)
GUISetFont(9, 1000, 0, $font)
Sleep(10)
$FileList = _FileListToArray("C:\Dropbox\Century21\Client Database\Buyers", "*", 2) ; get only folders with the quoted string
_ArrayDelete($FileList, 0) ; Throwing out the total folder count from the 0 index
For $folder In $FileList ; Loop over folders found.
GUICtrlSetData($list, $folder)
Next
EndIf
EndFunc

I keep getting this error:

"Func Buyers()

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

What am I doing wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

EndIf should be outside the function

If $BEvent = 1 Then

Func Buyers()
Opt("GUICoordMode", 3)
GUISetFont(9, 1000, 0, $font)
Sleep(10)
$FileList = _FileListToArray("C:DropboxCentury21Client DatabaseBuyers", "*", 2) ; get only folders with the quoted string
_ArrayDelete($FileList, 0) ; Throwing out the total folder count from the 0 index
For $folder In $FileList ; Loop over folders found.
GUICtrlSetData($list, $folder)
Next
EndFunc
EndIf
Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

Hi,

You have swapped EndIf and EndFunc, furthemore you can not write a func inside something (while, if).

Here you go :

If $BEvent = 1 Then
Buyers() ;call the func
EndIf

Func Buyers() ;func outside
Opt("GUICoordMode", 3)
GUISetFont(9, 1000, 0, $font)
Sleep(10)
$FileList = _FileListToArray("C:DropboxCentury21Client DatabaseBuyers", "*", 2) ; get only folders with the quoted string
_ArrayDelete($FileList, 0) ; Throwing out the total folder count from the 0 index
For $folder In $FileList ; Loop over folders found.
GUICtrlSetData($list, $folder)
Next
EndFunc   ;==>Buyers

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

maybe you should put so.

If $BEvent = 1 Then Buyers() ; to call the Function Correctly.

Share this post


Link to post
Share on other sites

Thanks all! Also, $BEvent is tied to a button, however, even though I don't press the button to call the function, the function is already executed - even though I didn't click any buttons. How can I tell the script to not execute a function unless it's called on?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If $BEvent is the variable storing the controlID (which is returned by a GUICtrlCreate... function) of the button, then do this:

Opt("GUIOnEventMode", 1) ; put this at the top of your script

GUICtrlSetOnEvent(-1, "Buyers") ; put this right after $BEvent is declared

That will trigger the function whenever the button is clicked

Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

Then the IF/Then statements aren't needed, correct?

Share this post


Link to post
Share on other sites

Correct ;)


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

I'm guessing that my problem isn't an If/then statement, but more of a question on how can I turn "on and off" a command in my script.

Generally, what I'm trying to do is have the button call a function that lists files in a specific directory. However, instead of listing files in each directory separately, it adds to the list of already found files. What I'm trying to do is have that list "refresh" into the new list.

Share this post


Link to post
Share on other sites

If you want to clear the list before adding the new files, then set the list's data to an empty string ("") before adding more data


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

Do you think a loop will be necessary?

$BuyerV = GUICtrlCreateButton("Buyers", 50, 50, 100, 30) ;creates buttons
$BEvent = GUICtrlSetOnEvent($BuyerV, "Buyers") ;assigns event to button

$list = GUICtrlCreateList("", 200, 50, 300, 290) ;creates a universal list window - however all files are displayed here instead of erased.
GUICtrlSetData($list, "")
GUISetState(@SW_SHOW)

Func Buyers()
Opt("GUICoordMode", 3)
GUISetFont(9, 1000, 0, $font)
Sleep(10)
$FileList = _FileListToArray("C:DropboxCentury21Client DatabaseBuyers", "*", 2) ; get only folders with the quoted string
_ArrayDelete($FileList, 0) ; Throwing out the total folder count from the 0 index
For $folder In $FileList ; Loop over folders found.
GUICtrlSetData($list, $folder)
Next
EndFunc

Share this post


Link to post
Share on other sites

Do you think a loop will be necessary?

Yes, you need a main loop between the gui and the funcs.

Here you go :

While 1
Sleep(1000) ;less cpu

;add code here to be executed everytime.
WEnd

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Wow, that loop saved up so much cpu!

Thanks for all your help guys, everything is working as expected now! :)

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