Jump to content

@Error issue


 Share

Recommended Posts

I tried searching for this but I guess the search engine doesn't like the "@" symbol.

Anyway, I have 2 While statements in my code they exit from the loop when an @error = -1 (pretty standard)

The problem is that my second while loop never happens because I believe it is still seeing the @Error = -1 from the last while loop.

I tried using the SetError command in many different places but that didn't work either. Maybe I am using it wrong? SetError("0") also tried SetError(0)

How do I get the @Error back to a non -1 state is there a different command?

Thanks,

Terry

Link to comment
Share on other sites

ok, so how would you set the @error just within code not in a function? Or clear it from it's previous setting?

Basically I want to read lines of a file from two different files one after another...

So I have 2 while loops back to back and the code is similar to this:

While 1

$line = FileReadLine($file1)

If @error = -1 Then ExitLoop

_DoSomeFunction1()

Wend

While 1

$line = FileReadLine($file2)

If @error = -1 Then ExitLoop

_DoSomeFunction2()

Wend

And the function in the second While loop never gets executed because when the code gets to the @error (in the second while) it exit's the loop. I know it ends here because I've stepped through it.

Thanks,

Terry

Link to comment
Share on other sites

@mattw112

Using :

If @error Then

will take last error, but if you specify error for the previous function like this :

$line = FileReadLine("yourfile.ext",1)
If $line = @error and @error = -1 then
;there is error and the return error is -1
EndIf

this would work :)

Cheers, FireFox

Link to comment
Share on other sites

ok, so how would you set the @error just within code not in a function? Or clear it from it's previous setting?

Basically I want to read lines of a file from two different files one after another...

So I have 2 while loops back to back and the code is similar to this:

While 1

$line = FileReadLine($file1)

If @error = -1 Then ExitLoop

_DoSomeFunction1()

Wend

While 1

$line = FileReadLine($file2)

If @error = -1 Then ExitLoop

_DoSomeFunction2()

Wend

And the function in the second While loop never gets executed because when the code gets to the @error (in the second while) it exit's the loop. I know it ends here because I've stepped through it.

Thanks,

Terry

@error is set to 0 when entering new function, you don't have to clear anything.

If you want to _DoSomeFunction2() after the error = -1 and before you exit the loop then do something like this:

While 1
    $line = FileReadLine($file2)
    If @error = -1 Then 
        _DoSomeFunction2()
        ExitLoop
   EndIf
Wend

And if you want to _DoSomeFunction2() regardless of error and exit loop after @error = -1 and after _DoSomeFunction2() then do this:

While 1
    $line = FileReadLine($file2)
    $error = @error
    _DoSomeFunction2()
    If $error = -1 Then ExitLoop
Wend

There are at least few more possibilities depending only (I guess) on what you really need.

@mattw112

Using :

If @error Then

will take last error, but if you specify error for the previous function like this :

$line = FileReadLine("yourfile.ext",1)
If $line = @error and @error = -1 then
;there is error and the return error is -1
EndIf

this would work :)

Cheers, FireFox

Woow man!! You are on completely different level.
Link to comment
Share on other sites

trancexx, not sure that will work...

These are simple Read lines from file while loops, @Error gets set when the end of the file is reached...

My problem is this gets carried over to the next while loop and it thinks the @error was set and exits the loop before it should.

The function only occurs after the exitloop statement because if you've reached the end of the file then you can't do the function on empty data.

Maybe I'm reading what you wrote wrong though...

Again my code is similar to this:

While 1

$line = FileReadLine($file1)

If @error = -1 Then ExitLoop

_DoSomeFunction1()

Wend

While 1

$line = FileReadLine($file2)

If @error = -1 Then ExitLoop

_DoSomeFunction2()

Wend

It seems like I should have an easy way to just say:

@Error = ""

And zero it out again?

Thanks,

Terry

Link to comment
Share on other sites

I get no problems with this code:

Sample:

$file1 = FileOpen ("File1.txt", 0)
$file2 = FileOpen ("File2.txt", 0)

If $file1 = -1 Then
    MsgBox(0, "Error", "Unable to open file 1.")
    Exit
EndIf

If $file2 = -1 Then
    MsgBox(0, "Error", "Unable to open file 2.")
    Exit
EndIf


While 1
    $line = FileReadLine($file1)
    If @error = -1 Then ExitLoop
    MsgBox (0, "", $line)
WEnd

MsgBox (0, "Done This Loop!", "Moving to next loop")

While 1
    $line = FileReadLine($file2)
    If @error = -1 Then ExitLoop
    MsgBox (0, "", $line)
WEnd

MsgBox (0, "Done This Loop Too!", "Both Loops used")

FileClose ($file1)
FileClose ($file2)

File1.txt

1
2
3
4
5

File2.txt

5
4
3
2
1
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...