Jump to content

Function in for / Next


Recommended Posts

I have a script that I want to convert to using variables so that I only have to have 1 iteration of the script and just use an array to process the next item in the array.What I am running into is an error within the function, "error:missing Next"  and I can't quite figure out where I am missing the boat.

Here is the code.  Some may recognize their incorporated suggestions 😎    Also,  how do I paste code in the forum so it shows up as it looks in SciTE 

Global $T[3] = ["A","B","C"]
Global $x

For $x = 0 to 2

Func _EXISTS($sFile = "C:\Users\XXXX\Downloads\$T[$x].csv", $iTimeout = 5000) ; $iTimeout in milliseconds
    Local $hTimer = TimerInit() ; start counting time
    While TimerDiff($hTimer) < $iTimeout
        If FileExists($sFile) Then Return True ; check if the file exists
        Sleep(100) ; do not hog the CPU
    WEnd ; if you reached this point, it means the file does not exist after timeout
    Return False
EndFunc   

If _EXISTS() = "True" Then
SplashTextOn("Display","It's There", 200,200,200,200)
sleep(2000)
splashoff

else 

SplashTextOn("Display","It's Missing", 200,200,200,200)
sleep(2000)
splashoff

next

exit

 

 

Edited by HTRN
Link to comment
Share on other sites

Something like this: untested

Global $T[3] = ["A","B","C"]
Global $x

For $x = 0 to UBound($T) - 1
    If  _EXISTS("C:\Users\XXXX\Downloads\" & $T[$x] & ".csv", 5000) = True Then
        SplashTextOn("Display","It's There", 200,200,200,200)
        sleep(2000)
        splashoff()
    else
        SplashTextOn("Display","It's Missing", 200,200,200,200)
        sleep(2000)
        splashoff()
    EndIf
next

Func _EXISTS($sFile = "C:\Users\XXXX\Downloads\$T[$x].csv", $iTimeout = 5000) ; $iTimeout in milliseconds
    Local $hTimer = TimerInit() ; start counting time
    While TimerDiff($hTimer) < $iTimeout
        If FileExists($sFile) Then Return True ; check if the file exists
        Sleep(100) ; do not hog the CPU
    WEnd ; if you reached this point, it means the file does not exist after timeout
    Return False
EndFunc

 

Edited by Subz
Forgot EndIf
Link to comment
Share on other sites

Thank you for the info and I actually got it to work in theory. Haven't tried it in my full blown script just yet,


BUT!! In typical fashion,  I have once again changed my mind about how I want part of  this script to run.  I will be posting a new question..

 

 

 

 

  

Link to comment
Share on other sites

10 hours ago, HTRN said:

Also,  how do I paste code in the forum so it shows up as it looks in SciTE 

 

When you're writing your post, there should be a bar above with Bold, underline, etc. There should be a "<>" icon for code. Paste your code in the window that pops up.

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