Sign in to follow this  
Followers 0
NELyon

Ubound returning wrong number?

9 posts in this topic

Ok, so i am trying to read the data within the <description> tag in the WikiHow's rss feed. I'm trying to take the description and set it into an Edit Box. It flashes for a minute and i can see that the data in entered, but then i get a Array variable has incorrect number of subscripts or subscript dimension range exceeded error. If i do it with a message box, it displays all of the message boxes, but gives the same error at the end. Heres the script.

#include <array.au3>
#Include <Inet.au3>
$a = _StrBetween(_INetGetSource("http://www.wikihow.com/feed.rss"), "<description>", "</description>")
$GUI = GUICreate("WikiHow's Latest HowTo's", 700, 700, 100, 50)
$Edit = GUICtrlCreateEdit("", 50, 50, 600, 600)
GUISetState()
For $i = 0 to UBound($a)
    GUICtrlSetData($Edit, $a[$i] & @CRLF)
Next

While 1
    Sleep(2000)
WEnd

; By Smoke_N
;
;
;
;
;
; Smoke_N Rocks

Func _StrBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)
    If $iSRE = -1 Or $iSRE = Default Then
        If $vCase = -1 Or $vCase = Default Then $vCase = 0
        If $vCase <> -1 And $vCase <> Default Then $vCase = 1
        Local $sHold = '', $sSnSStart = '', $sSnSEnd = ''
        While StringLen($sString) > 0
            $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
            $sHold &= StringLeft($sString, $sSnSEnd - 1) & Chr(1)
            $sString = StringTrimLeft($sString, $sSnSEnd)
        WEnd
        If Not $sHold Then Return SetError(1, 0, 0)
        $sHold = StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Local $aArray[UBound($sHold) - 1]
        For $iCC = 1 To UBound($sHold) - 1
            $aArray[$iCC - 1] = $sHold[$iCC]
        Next
        Return $aArray
    Else
        If $vCase = Default Or $vCase = -1 Then $vCase = '(?i)'
        If $vCase <> Default And $vCase <> -1 Then $vCase = ''
        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
    EndIf
EndFunc

Anyone know what's going on here?

Share this post


Link to post
Share on other sites



Seems _StringBetween() returns a 0 based array with data starting from element 0.

Add a -1 after the UBound

For $i = 0 to UBound($a) -1
    GUICtrlSetData($Edit, $a[$i] & @CRLF)
Next

:P

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I tried that, and it only returned the first description.

EDIT: Nope, it only returns the LAST one lol

Edited by D-Generation X

Share this post


Link to post
Share on other sites

guictrlsetdata sets the data, do a guictrlread & $a

Share this post


Link to post
Share on other sites

guictrlsetdata sets the data, do a guictrlread & $a

Uh, What?

I'm trying to set the data. It will only set the last entry though.

Share this post


Link to post
Share on other sites

Try this

#include <array.au3>
#Include <Inet.au3>
$source = _INetGetSource("http://www.wikihow.com/feed.rss")
;~ MsgBox(0, '', $source)

$a = _StrBetween($source, "<description>", "</description>")
$GUI = GUICreate("WikiHow's Latest HowTo's", 700, 700, 100, 50)
$Edit = GUICtrlCreateEdit("", 50, 50, 600, 600)
GUISetState()
Global $text
For $i = 0 to UBound($a) -1
    $text &= $a[$i] & @CRLF
Next
GUICtrlSetData($Edit, $text & @CRLF)

While 1
    Sleep(2000)
WEnd
; By Smoke_N
;
;
;
;
;
; Smoke_N Rocks

Func _StrBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)
    If $iSRE = -1 Or $iSRE = Default Then
        If $vCase = -1 Or $vCase = Default Then $vCase = 0
        If $vCase <> -1 And $vCase <> Default Then $vCase = 1
        Local $sHold = '', $sSnSStart = '', $sSnSEnd = ''
        While StringLen($sString) > 0
            $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
            $sHold &= StringLeft($sString, $sSnSEnd - 1) & Chr(1)
            $sString = StringTrimLeft($sString, $sSnSEnd)
        WEnd
        If Not $sHold Then Return SetError(1, 0, 0)
        $sHold = StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Local $aArray[UBound($sHold) - 1]
        For $iCC = 1 To UBound($sHold) - 1
            $aArray[$iCC - 1] = $sHold[$iCC]
        Next
        Return $aArray
    Else
        If $vCase = Default Or $vCase = -1 Then $vCase = '(?i)'
        If $vCase <> Default And $vCase <> -1 Then $vCase = ''
        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Yes! Thanks MHz

Share this post


Link to post
Share on other sites

When u set the data itll erase all old data, thus i was suggesting reading all the data and then adding the string then setting it so it doesnt overwrite what u already had in it, and of course MHZ showed another way.

Share this post


Link to post
Share on other sites

Yeah, i modded MHz's code and got what i was looking for.

THanks

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  
Followers 0