Sign in to follow this  
Followers 0
ralnee

Help Displaying Looped Data To Gui

4 posts in this topic

cnn_topstories.xmlI've banged my head for two days, and I can't find what's wrong in my "looping" logic... I'm parsing and looping through an XML file (this works great), but the GUI only shows the first "loop" multiple times, rather then different data per loop. (I hope this makes sense!!!)

Anyway, I've included the code below with a sample xml (rss) file attachment....Thanks in Advance

#include <GUIConstants.au3>
#include <File.au3>
#Include "C:\Program Files\AutoIt3\SciTE\cSnippet\includes\_XMLDomWrapper.au3"

_SetDebug(True)
opt("MustDeclareVars", 1)
Local $sXmlFile, $oOXml, $msg, $Form1, $ns
GUICreate("Feed List", 915, 333, 192, 125, -1)
GUISetBkColor(0xF0F0F0)

;Lets open the feed file
$sXmlFile = "C:\tmp\cnn_topstories.xml"
If FileExists($sXmlFile) Then
;ConsoleWrite($sXmlFile & " Exists" & @LF)
      $oOXml = _XMLFileOpen ($sXmlFile)
EndIf
_WriteGui()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
         ;;;;;;;
    EndSelect
WEnd
Exit
Func _RetFirst($aArray); return first item in an array
    If IsArray($aArray) Then
        Return $aArray[1]
    EndIf
EndFunc;==>_RetFirst
Func _StringPad($sText, $sChar, $iLen, $iFlag = 0); add text to string
    While StringLen($sText) < $iLen
        If $iFlag < 1 Then
            $sText = $sText & $sChar
        Else
            $sText = $sChar & $sText
        EndIf
    WEnd
    Return $sText
EndFunc;==>_StringPad
Func _ResizeGui($iht); resize gui to fit all buds.
    Local $a = WinGetPos("")
    WinMove("", "", $a[0], $a[1], $a[2], $iht + 40)
EndFunc;==>_ResizeGui
Func _WriteGui()
    Local $ITEM_XPath, $aNodeName, $x, $ITEM_Y[5], $z, $sRet 
    Local $CHANNEL_XPath, $IMAGE_XPath, $IMAGE_Y[1], $CHANNEL_Y[1] 
;Get Channel Name
    $CHANNEL_XPath = '//rss/channel'
    $CHANNEL_Y[0] = _RetFirst(_XMLGetField ("//rss/channel/title"))
    ConsoleWrite("CHANNEL NAME = " & $CHANNEL_Y[0] & @LF)
    If IsArray($CHANNEL_Y) Then
        GUICtrlCreateLabel($CHANNEL_Y[0], 6, 1, 175, -1)
    EndIf
;Get Channel Image
    $IMAGE_XPath = '//rss/channel/image'
    $IMAGE_Y[0] = _RetFirst(_XMLGetField ("//rss/channel/image/url"))
    ConsoleWrite("CHANNEL IMAGE URL = " & $IMAGE_Y[0] & @LF)
    
;Get Channel Items
    $ITEM_XPath = '//rss/channel/item'
   ;$aNodeName = _XMLGetChildNodes ($ITEM_XPath)
   ;If $aNodeName[0] > 0 Then
        $sRet = _XMLSelectNodes ($ITEM_XPath)
    ;_ArrayDisplay($aNodeName,"Node Names")
        If IsArray($sRet) Then
        ;_ArrayDisplay($sRet,"Node Names")
            GUISetState(@SW_SHOW)
            _ResizeGui(40 * $sRet[0])
            GUISetState(@SW_LOCK)
                For $x = 1 To $sRet[0] 
                    If $sRet[$x] = "item" Then
                    ;ConsoleWrite($sRet[0] & @CRLF)
                    ;ConsoleWrite($sRet[$x] & @CRLF)
                        $ITEM_Y[0] = _RetFirst(_XMLGetField ("//rss/channel/item/title"))
                        $ITEM_Y[1] = _StringPad(_RetFirst(_XMLGetField ("//rss/channel/item/link")), " ", 18)
                        $ITEM_Y[2] = _StringPad(_RetFirst(_XMLGetField ("//rss/channel/item/pubDate")), " ", 21)
                        $ITEM_Y[3] = _StringPad(_RetFirst(_XMLGetField ("//rss/channel/item/description")), " ", 24)
                        $z = 40* ($x - 1)   
                        GUICtrlCreateLabel($ITEM_Y[2], 138, $z, 175, -1)
                        GUICtrlCreateLabel($ITEM_Y[0], 313, $z, 325, 30,-1)
                        GUICtrlCreateLabel($ITEM_Y[3], 513, $z, 525, 30, -1)
                    ;GUICtrlCreateLabel("        " & $y[1], 16, $z, 150, -1)
                    ;_ArrayDisplay($y,"Data")
                        GUISetState(@SW_UNLOCK)
                        ConsoleWrite($x & @CRLF)
                    EndIf
                Next
        EndIf
   ;EndIf
EndFunc;==>_WriteGui

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

i would suggest...

you create the labels first, then use guictrlsetdata() to update them in the function/loop

or create an edit and use guictrlsetdata() to update the info inside the edit box

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks, I try it and see how it works.....

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