Jump to content
Sign in to follow this  
Zepx

abou @error

Recommended Posts

Hi,

I've done some testings, but I still don't get it after some testings...

Basically lets say:

$GetStrBetween = _StringBetween('http://link', 'http://', 'link')
If @error Then
MsgBox(0, "", "Can't Find Between")
Else
MsgBox(0, "", "Found Between!")

It doesn't find a between, so it should say Can't Find between.

From the Help File, if _StringBetween doesn't find anything between, @error will be set to 1. Using the expression If @error, I get an Error instead, or in other words, it doesn't proceed with the "Can't Find between".

Any ideas what's wrong?

Share this post


Link to post
Share on other sites

Seems like an error in the UDF to me

#include <string.au3>

$GetStrBetween = _StringBetween('http://link', 'http://', 'link')

MsgBox(0x0, @error, $GetStrBetween & @CRLF & IsArray($GetStrBetween))

;Success: A 0 based $array[0] contains the first found string. 
;Failure: 0 
;@Error: 1 = No inbetween string found.

8)

Share this post


Link to post
Share on other sites

Something very odd about that example Val is that the IsArray should at least be returning 0, right? I'm just getting a completely blank MsgBox.

But get this, I added a VarGetType:

MsgBox(0x0, @error, VarGetType($GetStrBetween) & @CRLF & IsArray($GetStrBetween))

And now I get

Array
1

Seems rather buggy to me...

*Edit: And I was referring to AutoIt's behaviour, but the UDF is a little buggy as well.

Edited by Saunders

Share this post


Link to post
Share on other sites

Yes Saunders... I agree!

Just found another...

#Include <File.au3>
#Include <AutoitInfo.au3>

; Straight from help *****************************

$FileList=_FileListToArray(@WindowsDir & "\cursors\*.cur")

If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

;@Error: 1 = Path not found or invalid 
; 2 = Invalid $sFilter 
; 3 = Invalid $iFlag 
; 4 = No File(s) Found 

; straight from help ********************************

_AutoitInfoDisplay(@Error,"_FileListToArray",1) ; this shows the error number and  message
;
;

Saunders.... Notice the cur file??? I liked you last post about GUI/cursor.. I am going to put it in Autoit Wrappers...thx

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

Yes Saunders... I agree!

Just found another...

#Include <File.au3>
#Include <AutoitInfo.au3>

; Straight from help *****************************

$FileList=_FileListToArray(@WindowsDir & "\cursors\*.cur")

If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

;@Error: 1 = Path not found or invalid 
; 2 = Invalid $sFilter 
; 3 = Invalid $iFlag 
; 4 = No File(s) Found 

; straight from help ********************************

_AutoitInfoDisplay(@Error,"_FileListToArray",1) ; this shows the error number and  message
;
;oÝ÷ Ù&®×«°Ú-Ç­ç.­ø¥xbçr¢éZ²Úh²Ö¢ëFPܺ»(¬¦§Ú)ºØ­p.¶­Z¶©¥êì¶|þ«¨µâ7ö÷¥¢Ëm­§$¡÷±iËeËZµ» ËZV«zÖ¥gßÖèºÛ§²êÞN®º+©Ý)à¡ð.¶-±ç¦²Úyø§xíç±ê¶nÞ±Êâ¦Ü¨ºÈhºW`z׫®oÝ÷ Ù(hºW[y«­¢+Ù%MÑÉ¥¹%¹MÑÈ¡¥±ÑÑÑÉ¥ ÀÌØíÍAÑ ¤°ÅÕ½ÐíÅÕ½Ðì¤ôÀQ¡¸IÑÕɸMÑÉÉ½È Ä°Ä°ÅÕ½ÐìÅÕ½ÐìoÝ÷ Ù8b³¥Æ®±ì¨ºÚ zÛayìiyË^uêë¢oÝ÷ ØÚ)j»bréZ®·­º¹ïj[Éبçh®º+

Note the StringRegExp is flag type 3, which returns an empty array and sets @error = 1 on finding no matches. So If IsArray() is True and it returns the empty array without resetting @error.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The code that produces your anomalous results in _StringBetween() is:

AutoItFunc _StringBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)

        ; ...

        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
        
        ; ...
EndFunc   ;==>_StringBetween

Note the StringRegExp is flag type 3, which returns an empty array and sets @error = 1 on finding no matches. So If IsArray() is True and it returns the empty array without resetting @error.

Actually I looked at that first too, but notice that the thread starter was not using regular expression mode (5th param in _StringBetween left empty, defaults to non-regular expression matching). I looked at that part of the code, but was fairly baffled at it, so I'm just going to try bringing this thread to Smoke's attention (says he's the function author). I'm also going to ask Smoke that the regex line (that you quoted incidentally) be adjusted to (.+?) instead of (.*?). This will ensure that it either finds something, or sets @error, because code like this: StringRegExp('AB', 'A(.*?)B', 1) will not set @error, as it doesn't HAVE to find something between A and B, but using + it does.

Share this post


Link to post
Share on other sites

Actually I looked at that first too, but notice that the thread starter was not using regular expression mode (5th param in _StringBetween left empty, defaults to non-regular expression matching). I looked at that part of the code, but was fairly baffled at it, so I'm just going to try bringing this thread to Smoke's attention (says he's the function author). I'm also going to ask Smoke that the regex line (that you quoted incidentally) be adjusted to (.+?) instead of (.*?). This will ensure that it either finds something, or sets @error, because code like this: StringRegExp('AB', 'A(.*?)B', 1) will not set @error, as it doesn't HAVE to find something between A and B, but using + it does.

Ditto!!!

A Little to much Salt today.... :)

.... But now I don't have to bring this to Smoke's attention

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

Ditto!!!

A Little to much Salt today.... ^_^

.... But now I don't have to bring this to Smoke's attention

8)

Nonsense! You can never be too Psalty!

This modification generates the proper error when the string between is null:

#include <array.au3>

$GetStrBetween = _StringBetween('http://this.link', 'http://', 'link')
MsgBox(64, "@error = " & @error, "IsArray($GetStrBetween) = " & IsArray($GetStrBetween))
If IsArray($GetStrBetween) Then _ArrayDisplay($GetStrBetween, "Debug: $GetStrBetween")

$GetStrBetween = _StringBetween('http://link', 'http://', 'link')
MsgBox(64, "@error = " & @error, "IsArray($GetStrBetween) = " & IsArray($GetStrBetween))
If IsArray($GetStrBetween) Then _ArrayDisplay($GetStrBetween, "Debug: $GetStrBetween")


;==================================================================================================
; Function Name:        _StringBetween($sString, $sStart, $sEnd, $vCase, $iSRE)
;
; Parameters:           $sString:     The string to search
;                       $sStart:      The beginning of the string to find
;                       $sEnd:        The end of the string to find
;                       $vCase:       Case sensitive search:  Default or -1 = Not case sensitive
;                       $iSRE:        Choose whether to use StringRegExp or Regular Sting Manipulation to get the result
;                                     Default or -1:  Regular String Manipulation used (Non StringRegExp())
;
; Description:          Returns the string between the start search ($sStart) and the end search ($sEnd)
;
; Requirement(s)        AuotIt Beta 3.2.1.8 or higher
;
; Return Value(s)       On Success:    A 0 based array [0] contains the first found string
;                       On Failure:    @Error = 1: No inbetween string was found
;
; Author(s):            SmOke_N
;                       Thanks to Valik for helping with the new StringRegExp (?s)(?i) isssue
;                       Modified by PsaltyDS 13Dec07 to detect null string found correctly
;==================================================================================================

Func _StringBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)
    If $iSRE = -1 Or $iSRE = Default Then
        If $vCase = -1 Or $vCase = Default Then
            $vCase = 0
        Else
            $vCase = 1
        EndIf
        Local $sHold = '', $sSnSStart = '', $sSnSEnd = ''
        While StringLen($sString) > 0
            Local $sTemp = ""
            $sSnSStart = StringInStr($sString, $sStart, $vCase)
            If Not $sSnSStart Then ExitLoop
            $sString = StringTrimLeft($sString, ($sSnSStart + StringLen($sStart)) - 1)
            $sSnSEnd = StringInStr($sString, $sEnd, $vCase)
            If Not $sSnSEnd Then ExitLoop
            $sTemp = StringLeft($sString, $sSnSEnd - 1)
            If $sTemp <> "" Then $sHold &= $sTemp & Chr(1)
            $sString = StringTrimLeft($sString, $sSnSEnd)
        WEnd
        If $sHold = "" Then Return SetError(1, 0, 0)
        $sHold = StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Local $avArray[UBound($sHold) - 1]
        For $iCC = 1 To UBound($sHold) - 1
            $avArray[$iCC - 1] = $sHold[$iCC]
        Next
        Return $avArray
    Else
        If $vCase = Default Or $vCase = -1 Then
            $vCase = '(?i)'
        Else
            $vCase = ''
        EndIf
        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_StringBetween

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If you guys did the expression correctly, you'd see there was no error:

$GetStrBetween = _StringBetween('http://link', 'http:\/\/', 'link')

Edit:

I'll iterate ...

1. You opted for the RegExp search method.

2. You must use RegExp rules.

So, if you had written the expression correctly for your choice to begin with, you would have gotten the results expected.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

If you guys did the expression correctly, you'd see there was no error:

$GetStrBetween = _StringBetween('http://link', 'http:\/\/', 'link')

Edit:

I'll iterate ...

1. You opted for the RegExp search method.

2. You must use RegExp rules.

So, if you had written the expression correctly for your choice to begin with, you would have gotten the results expected.

Uhmm... except the example leaves the $iSRE parameter off, so it's NOT SRE...

To be specific, my tweak in post #6 was about the SRE half of _StringBetween(), then Saunders pointed out the OP was about non-SRE. The code in post #9 is about non-SRE "regular string". And the code in both cases is just inteded to match the function behavior to the documentation. If the behavior of the function is as intended (very possible), then the help file and function header text should reflect it.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If you guys did the expression correctly, you'd see there was no error:

$GetStrBetween = _StringBetween('http://link', 'http:\/\/', 'link')

Edit:

I'll iterate ...

1. You opted for the RegExp search method.

2. You must use RegExp rules.

So, if you had written the expression correctly for your choice to begin with, you would have gotten the results expected.

Man, I am so lost today, it ain't even funny!

according to the function

Func _StringBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)

If $iSRE = -1 Or $iSRE = Default Then...

The first three are ( 1- the string ) ( 2- where to start) and ( 3-where to end)

We did not use the regexpress

( talk about a loser today, you should see my post in the developer thread)

... and I'm the guy who said to much Salt today.... geeze, I need to get a life!!!

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

Besides... I use this one anyway

Func _StringBetweenA($s_String, $s_Start, $s_End = 0) ; wOuter
    $s_Start = StringInStr($s_String, $s_Start)+StringLen($s_Start)
    return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End)-$s_Start)
EndFunc

... So there!!!!

8)

Just because you need a little more Psalt...

That only returns the first between-string, the regular function returns an array all matching between-strings.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Well. What the hell am I supposed to do with more than 1 anyways!!!...???

:)

If I needed a second opinion, i would just call it again.... ^_^

8)

SSSSSssssssip... needs just a touch more Psalt. :)

If you run it again it will just give the first match again.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Just had a debate about this with PsaltyDS, and I publicly state me being incorrect. I just assumed we were using RegExp... I might have wrote the func, but I don't use it :)

I wouldn't expect it to return an array in this case, if the char was null.. so use salty's fix... and salty should submit the fix to Jos.

Being bogged down at work today and a huge project I'm working on, I'm only catching bits and pieces of posts/arguements, so I'll make a graceful exit for the rest of the day lol...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×
×
  • Create New...