StringReplace sets Errorlevel - why? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

StringReplace sets Errorlevel - why?

20 Jul 2017, 09:30

Friends of automation,
I have downstripped my script to these few lines. It turns out that StringReplace sets an error level - in contrast to what I read in the documention.
Have I mis-interpreted the doc?

Code: Select all

  Loop, READ, %fileName%, %outFile% 
  {
    thisLine := A_LoopReadLine
    MsgBox 1 ErrorLevel = %ErrorLevel%            ; => 0
    StringReplace, thisLine, thisLine, -, |, all   
    MsgBox 2 ErrorLevel = %ErrorLevel%            ; => 1
  }
In the full script I test error level after the assignment of thisLine and issue a messag "reading error" if ErrorLevel is not 0. It took me a while to find that StringReplace sets it.
As a solution I now set Errorlevel to 0 just after StringReplace ... but this should IMHO not be necessary.

Do You spot an error there?
Klaus Daube, Zürich, CH
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: StringReplace sets Errorlevel - why?  Topic is solved

20 Jul 2017, 11:16

Use StrReplace() instead
ErrorLevel
StrReplace: ErrorLevel is not set.
User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

Re: StringReplace sets Errorlevel - why?

20 Jul 2017, 12:12

Thank You, AlphaBravo!
Klaus Daube, Zürich, CH
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: StringReplace sets Errorlevel - why?

21 Jul 2017, 22:03

In answer to the original question: StringReplace sets ErrorLevel to indicate whether the operation was successful. The documentation is quite clear:
StringReplace: When the last parameter is UseErrorLevel, ErrorLevel is given the number occurrences replaced (0 if none). Otherwise, ErrorLevel is set to 1 if SearchText is not found within InputVar, or 0 if it is found.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 81 guests