Jump to content

Recommended Posts

Posted

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?

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

 

Posted

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.

Posted

maybe you should put so.

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

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?

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

 

Posted

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.

Posted

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

 

Posted

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
Posted

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.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...