dynamitemedia

xmldom into array and then use outside function

10 posts in this topic

i have the following snippet...   now its working but i have it inside a function and want to be able to use   $aThumb[$i]  outside the function in the rest of the script, i tried return and keep getting this error  "Invalid keyword at the start of this line.:"  

Global $iRows = UBound($a, $UBOUND_ROWS) 
    Global $iCols = UBound($a, $UBOUND_COLUMNS)

          $oID = $oID + 1
          $oURL = $oString.selectSingleNode("./url")
          $oName = $oString.selectSingleNode("./name")
          $oCategory = $oString.selectSingleNode("./category")
          $oThumb = $oString.selectSingleNode("./image")
          $oLanguage = $oString.selectSingleNode("./language")

         $aThumb = [$iRows]
         _ArrayAdd($aThumb, $oThumb.text)

         For $i = 1 To UBound($aThumb) - 1
             ConsoleWrite($oID & @TAB & $aThumb[$i] & @CRLF)
         Next
          
    Next
   ConsoleWrite( "rows: " & $iRows & @CRLF)

Thanks for your help

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Have you ever heard that functions can return a result? No, then smiley38.gif (Language Reference - User Functions)

Or show your (yet not) runable script, how you tried it.

Edited by AutoBert

Share this post


Link to post
Share on other sites

wow no need to be answer only to be rude...     thought was such a general question i had given enough info

Global Enum $iServerName, $iUBound

      Local $sText = ""
      For $i = 1 To Random(5, 20, 1)
         $sText &= Chr(Random(65, 122, 1))
      Next

       $link = "http://www.my site.to/api/live.xml?t=" & $sText   ; private api 
      ConsoleWrite($link  & @CRLF)

       Local $dBinary = InetRead($link)
       $sConverted = BinaryToString($dBinary)


       $strXMLStructure = "//channels/channel"
       $oXML = ObjCreate("Microsoft.XMLDOM")
       $oXML.loadXML($sConverted)

       $oStrings = $oXML.selectNodes($strXMLStructure)


       $oID = 0

Local $a
      For $oString In $oStrings

       If IsArray($a) Then
        ReDim $a[UBound($a)+1][$iUBound]
    Else
        Local $a[1][$iUBound]
    EndIf


    Global $iRows = UBound($a, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($a, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.

          $oID = $oID + 1
          $oURL = $oString.selectSingleNode("./url")
          $oName = $oString.selectSingleNode("./name")
          $oCategory = $oString.selectSingleNode("./category")
          $oThumb = $oString.selectSingleNode("./image")
          $oLanguage = $oString.selectSingleNode("./language")

         Local $aThumb = [$iRows]
         _ArrayAdd($aThumb, $oThumb.text)

         For $i = 1 To UBound($aThumb) - 1
             ;ConsoleWrite($oID & @TAB & $aThumb[$i] & @CRLF)
            local $bThumb = 22
         Next
          ; ConsoleWrite($oID & @TAB & $oName.text & @TAB & $urlString & @TAB & $oThumb.text & @TAB & $oCategory.text & @TAB & $oLanguage.text & @CRLF )

            Return $bThumb

           Next

   ConsoleWrite( "rows: " & $iRows & @CRLF)

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

dymanitemedia,

"Return" is not allowed from GLOBAL scope, meaning that it is only used within a function, normally to return a value to the caller.

Your code is not runnable as several vars are undefined, perhaps some includes are missing?

kylomas

Also, I would make sure that $ostrings is an object and what are you trying to do with variable $a?

Edited by kylomas
additional info

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

sorry the includes did get missed!  full code is here:
 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <Date.au3>

Global Enum $iServerName, $iUBound

      Local $sText = ""
      For $i = 1 To Random(5, 20, 1)
         $sText &= Chr(Random(65, 122, 1))
      Next

       $link = "http://my private api /api/live.xml?t=" & $sText
      ConsoleWrite($link  & @CRLF)

       Local $dBinary = InetRead($link)
       $sConverted = BinaryToString($dBinary)


       $strXMLStructure = "//channels/channel"
       $oXML = ObjCreate("Microsoft.XMLDOM")
       $oXML.loadXML($sConverted)

       $oStrings = $oXML.selectNodes($strXMLStructure)


       $oID = 0

Local $a
      For $oString In $oStrings

       If IsArray($a) Then
        ReDim $a[UBound($a)+1][$iUBound]
    Else
        Local $a[1][$iUBound]
    EndIf


    Global $iRows = UBound($a, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($a, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.

          $oID = $oID + 1
          $oURL = $oString.selectSingleNode("./url")

          $oName = $oString.selectSingleNode("./name")
          $oCategory = $oString.selectSingleNode("./category")
          $oThumb = $oString.selectSingleNode("./image")
          $oLanguage = $oString.selectSingleNode("./language")

         Local $aThumb = [$iRows]
         _ArrayAdd($aThumb, $oThumb.text)

         For $i = 1 To UBound($aThumb) - 1
             ;ConsoleWrite($oID & @TAB & $aThumb[$i] & @CRLF)
            local $bThumb = 22
         Next
          ; ConsoleWrite($oID & @TAB & $oName.text & @TAB & $urlString & @TAB & $oThumb.text & @TAB & $oCategory.text & @TAB & $oLanguage.text & @CRLF )

            Return $bThumb

           Next

   ConsoleWrite( "rows: " & $iRows & @CRLF)

I need the thumbs , all of them in the gui...  the thing is i want to be able to grab more this just this xml, if it was meant to ONLY use one xml file i can hard code it work just fine...  but each api will have different xml structure and i need to code to work with each one
 

 

EDIT/ Additions

the $a is used to get the count of rows and columns

i use the rows to know how many buttons i will need to make

Edited by dynamitemedia
adding what $a is for

Share this post


Link to post
Share on other sites

so how can i use the info from this XML ? 

I want to use it to build the gui

Share this post


Link to post
Share on other sites

@jdelaney

Since you see, the expert at using the xml dom, any ideas how i can do this... I would really like to put this above in a function and still use each of the xml nodes if needed say i click on button 56  it would go to node 56 and get that info

Share this post


Link to post
Share on other sites

Seeing your script in #5 and checking:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /AU3Check /in "C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3"
+>12:43:50 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.1)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3
"C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3"(71,27) : error: 'Return' not allowed from global scope.
            Return $bThumb
~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3 - 1 error(s), 0 warning(s)
!>12:43:53 AU3Check ended. Press F4 to jump to next error.rc:2
+>12:43:53 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 5.195

i am wondering about your ignorance.:

On ‎28‎.‎01‎.‎2016 at 10:31 PM, kylomas said:

"Return" is not allowed from GLOBAL scope, meaning that it is only used within a function, normally to return a value to the caller.

 This snippet:

Local $a
      For $oString In $oStrings

       If IsArray($a) Then
        ReDim $a[UBound($a)+1][$iUBound]
    Else
        Local $a[1][$iUBound]
    EndIf

show's me:

  • there you need the to learn the basic's. A variable $a just declared without any dimension testing against Array is nonsence. It couldn't be a array, nothing is happend.  So smiley38.gif work hard from the beginning to the end, including testing the examples of the needed functions.
  • or your script isn't complete, then post your complete script. 

Share this post


Link to post
Share on other sites

AutoBert,

You have already been told once today about the manner in which you are replying - this is the second and final warning you get to change your ways. If your RTFM emoticon appears again - or if you express a similar unwelcoming attitude in future - your future in this community will be in serious jeopardy.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

these are help forums to ask for help..  why do you feel the need to insult and be rude to people asking for help?

that snippet that shows you   with your rant  was taken from here and it serves a purpose
https://www.autoitscript.com/forum/topic/179751-searching-fields-within-xml/?do=findComment&comment=1290314

I use it to get how many noded(rows) in the array

Global $iRows = UBound($a, $UBOUND_ROWS)

it works, is it right i am not 100% sure  but that works with giving me the right amount of nodes from the XML

as far as leaving the "Return" in there i  did uncomment it in my code.

and it is the whole code and works, when connected to the right  xml.   

I just want to make this a function  cause the images in the nodes will complete the gui.  

Instead of being rude maybe offering a alternate solution would be the way to go

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

  • Similar Content

    • Eli_jahbot
      By Eli_jahbot
      My esteemed Autoits I need your help once again.
      I'm trying to figure out how to create a loop that gets 1 value from an array and repeats until each value from the array has been used. I have never used arrays before and I know once I learn more things should get easier for me. 
      Here is what Im trying to do:
      -Have an array of values that determine what application i log into. ex: app1, app2, app3, app4 etc.
      -Have a loop that repeats a process sequentially using each value in the array to finish the process for each app1, app2, app 3 and so forth. I have 30 apps that I need to update on a regular basis and getting this sorted out is what I perceive to be the best way to do it.
      Here is my feeble attempt that obviously fails:
      #include <msgboxconstants.au3>
      #include <Constants.au3>
      #include <array.au3>
      Login()
      Func Login()
          local $array[30] = ["10", "11", "12",etc etc]
          ;;Local $site = InputBox("ERx Site","What site do you want to login as?","","")
          Local $userid = InputBox("ERx Login", "What is your username?", "", "")
          Local $Passwd = InputBox("Security Check", "Enter your UAT password.", "", "*")
      for $1 = 1 to 30(I need to do the same steps in 30 different apps)
      run("Z:launch.exe")
      WinWaitActive("Input")
      Send (Sequential ARRAY VALUE HERE)
      Send("{ENTER}")
      WinWaitActive("window")
      Send($userid)
      Send("{TAB}")
      send($Passwd)
      Send("{ENTER}")
      WinWaitActive("[CLASS:SunAwtDialog]")
      Sleep(500)
      WinClose("Home Page")
      Next
      EndFunc
       
      your help is greatly appreciated.
      Thanks for your time
    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • cosmos
      By cosmos
      Edit: Just realised this was posted in the wrong forum! I guess the Mods will move it to either "AutoIt General Help and Support" or "AutoIt Technical Discussion".
      Do you use type checking? Or do you choose not to type check?
      I was trying to think of the simplest way to do a type check without typing arguments more than once and I came up with:
      Func displayPerson($firstName, $lastName, $age) ; -- TYPE CHECK -- Local $typeCheck = ("" _ & IsString($firstName) _ & IsString($lastName) _ & IsNumber($age) _ ) If (StringInStr($typeCheck, "0")) Then MsgBox(16, "Type Error: displayPerson()", $typeCheck) ; -- FUNCTION -- MsgBox(0, "", $firstName & " " & $lastName & " (" & $age & ")") EndFunc The only catch with this method is that it produces a very simplistic error message. Even still, the fact that you only have to type out arguments once makes it a reasonable approach, in my opinion. The same logic can also be used for making function contracts (for example: $firstName mustn't be an empty string etc...).
      What do you think? How do you go about such things?
    • SJF85
      By SJF85
      Hey, just wondering if anyone has ever encountered intermittent COM Object Errors with Microsoft.XMLDOM pulling node values. I'm currently getting "Bad Variable Type" intermittently, and simply running the script again would allow it to get further in the parsing loop, only to encounter the error again. The data is persistent, and it is always a string.
      Here's a snippet of where the error event occurs
      $Target = "Item001" $SearchItem = $oXML.SelectNodes("//Items/Name[. = """&$Target&"""]") If $SearchItem.Length==1 Then AddToLog("XML: Found a match for """&$Target&""", Gathering details...") $TargetItem = $SearchItem.Item(0).ParentNode $ItemSKU = XMLGetValue($TargetItem, "SKU") Endif and here's the snip of my XMLGetValue function where the error is always triggered on the $Value = ...
      Func XMLGetValue($Node="", $ValueName="", $NestLevel=0) ... If $Node.GetElementsByTagName($ValueName).Item(0).ChildNodes.Length==1 Then $Value = $Node.GetElementsByTagName(String($ValueName)).Item(0).ChildNodes(0).NodeValue Else ...Tell me there are more than one result for the target Endif ... EndFunc I added the string() as a counter measure but that doesnt fix the error. The XML file contains standard data with no attributes or anything funky.
      The weird thing is that if i reboot my workstation it might get all the way through, and then if i run it again it may burp some where throughout the loop process (For each item, get SKU, Add SKU to array, Do stuff with array contents afterwards). 
      I have added sleep timers to my loops to try and pace the XML requests in case it was a sort of buffer underrun issue but im not certain whats going on.
       
      Again, i could run the script and it would work perfectly and then fail another time. I've read up about readyState, but i dont know how to incorporate it in my script.
      Has anyone seen this before? Thanks in advance for your help.
       
    • NiftRex
      By NiftRex
      I'm trying to get an array from a website so that I can just get the url, but I am not sure how. I read a bit of arrays but I have a feeling I'd have to be writing a lot more than what I should be. I will include the script I have so far and the API url for what I want.
       
      API: https://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1 (I want the 'url' array that contains the url)
       
      Code:
      #include <MsgBoxConstants.au3> #include <Inet.au3> #include <Array.au3> $site = _INetGetSource('http://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1') MsgBox($MB_SYSTEMMODAL, "Title", $site[1])