Jump to content
Sign in to follow this  
mattw112

@Error issue

Recommended Posts

mattw112

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

Share this post


Link to post
Share on other sites
Valuater

I do not believe that is the problem, you have to show code for help though

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
FireFox

@mattw112

SetError is only used in functions to set the return error flag, like you say : it return generaly -1

Cheers, 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
mattw112

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

Share this post


Link to post
Share on other sites
FireFox

@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


 

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
trancexx

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.

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
FireFox

@trancexx

drunk too much the day I posted this :)

Cheers, FireFox.

Edited by 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
mattw112

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

Share this post


Link to post
Share on other sites
BrettF

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

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  

×