Jump to content

For...next help with scheme


Terenz
 Share

Recommended Posts

Hello again,

I need to save a variable with this scheme:

<fin> ; starting value

<aa>aaa</aa>

<aa>bbb</aa>

<aa>ccc</aa>

<aa>ddd</aa>

</fin> ; finish value

Now the first problem, i don't know if the aaa bbb ccc ddd are always in a row of four, can be also:

<fin> ; starting value

<aa>aaa</aa>

<aa>bbb</aa>

</fin> ; finish value

Or three or only one...Now the second problem, the scheme not starting always with <fin> but every two "row" with <fin = test>

<fin> ; starting value

<aa>aaa</aa>

<aa>bbb</aa>

</fin> ; finish value

<fin = test> ; starting value with test

<aa>aaa</aa>

<aa>bbb</aa>

</fin> ; finish value

<fin> ; normal starting value

<aa>aaa</aa>

<aa>bbb</aa>

</fin> ; finish value

<fin = test> ; starting value with test

<aa>aaa</aa>

<aa>bbb</aa>

</fin> ; finish value

This is my starting attempt:

local $aArray[8] = ["aaa","bbb","ccc","ddd","eee","fff","ggg","hhh"]
Local $End = '<fin>' & @CRLF

For $x = 0 To UBound($aArray) -1
    $End &= '<aa>' & $aArray[$x] & '</aa>' & @CRLF
    If $x = 3 then $End &= '</fin>' & @CRLF & '<fin = test>' & @CRLF
Next
$End &= '</fin>'

MsgBox(0,0,$End)

Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

LOL

I have an array with an indefinite number of item, example 8

I need to separate this element in a "group", example group of 4 items:

<fin> ; starting value
<aa>aaa</aa> ; item 1
<aa>bbb</aa> ; item 2
<aa>ccc</aa> ;item 3
<aa>ddd</aa> ;item 4
</fin> ; finish value

 

Every two "group" instead of starting with <fin> ( like the first ) i need to start with <fin = test>

<fin> ; starting value
<aa>aaa</aa> ; item 1
<aa>bbb</aa> ; item 2
<aa>ccc</aa> ;item 3
<aa>ddd</aa> ;item 4
</fin> ; finish value
<fin = test> ; starting value this time is changed
<aa>eee</aa> ; item 5
<aa>fff</aa> ; item 6
<aa>ggg</aa> ;item 7
<aa>hhh</aa> ;item 8
</fin> ; finish value
 
Is more clear now?
Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

??

local $aArray[16] = ["aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","aaa","bbb","ccc","ddd","eee","fff","ggg","hhh"]
Local $End = '<fin>' & @CRLF

For $x = 0 To UBound($aArray) -1
    $End &= '<aa>' & $aArray[$x] & '</aa>' & @CRLF
    If Not Mod($x,2) then $End &= '</fin>' & @CRLF & '<fin = test>' & @CRLF
Next
$End &= '</fin>'

MsgBox(0,0,$End)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

@Firefox Sorry but an example of what?

@JohnOne no, your result is:

<fin>
<aa>aaa</aa>
</fin>
<fin = test>
<aa>bbb</aa>
<aa>ccc</aa>
</fin>
<fin = test>
<aa>ddd</aa>
<aa>eee</aa>
</fin>

The expected result is:

<fin>
<aa>aaa</aa>
<aa>bbb</aa>
<aa>ccc</aa>
<aa>ddd</aa>
</fin>
<fin = test>
<aa>eee</aa>
<aa>fff</aa>
<aa>ggg</aa>
<aa>hhh</aa>
</fin>
<fin>
<aa>iii</aa>
<aa>jjj</aa>
<aa>kkk</aa>
<aa>lll</aa>
</fin>
<fin = test>
<aa>mmm</aa>
<aa>nnn</aa>
<aa>ooo</aa>
<aa>ppp</aa>
</fin>





and so on

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Local $aArray[16] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp"]
Local $End = '<fin>' & @LF

Local Const $split = 4

For $x = 0 To UBound($aArray) - 1
$End &= '<aa>' & $aArray[$x] & '</aa>' & @LF
If Mod($x +1, $split) = 0 Then $End &= '</fin>' & (($x < UBound($aArray) - 2) ? @LF & '<fin = test>' & @LF : '')
Next

ConsoleWrite($End & @LF)

Link to comment
Share on other sites

Or use the _Iif function.

#include <Misc.au3>

Local $aArray[16] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp"]
Local $End = '<fin>' & @LF

Local Const $split = 4

For $x = 0 To UBound($aArray) - 1
$End &= '<aa>' & $aArray[$x] & '</aa>' & @LF
If Mod($x + 1, $split) = 0 Then $End &= '</fin>' & _Iif(($x < UBound($aArray) - 2), @LF & '<fin = test>' & @LF, '')
Next

ConsoleWrite($End & @LF)
Link to comment
Share on other sites

I'm still not getting the point of constructing this sudo-XML structure.

You create it, and then what, do you need to parse it up to deconstruct it again?  If that's the case, I'd suggest valid XML, and xmldom...or an ini file.

xml sample (with some edits to make valid structure):

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.preserveWhiteSpace = True
$oXML.loadXML('<?xml version="1.0" encoding="utf-8"?><fins/>' & @CRLF)

Local $aArray[14] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn"]

$oRoot = $oXML.selectSingleNode("//fins")

$bIsTest = False
$oFin = ""

For $i = 0 To UBound($aArray)-1
    If IsInt($i/4) Then
        If IsObj($oFin) Then
            $oRoot.appendChild($oFin)
            $oFin = ""
        EndIf
        $oFin = $oXML.createElement("fin")
        If $bIsTest Then
            $oFin.setAttribute("key","test")
        EndIf
        $bIsTest = Not $bIsTest
    EndIf

    $oAA = $oXML.createElement("aa")
    $oAA.text = $aArray[$i]
    $oFin.appendChild($oAA)
Next
If IsObj($oFin) Then $oRoot.appendChild($oFin)
For $oChild In $oRoot.childNodes
    ConsoleWrite(StringRegExpReplace($oChild.xml,"><",">" & @CRLF & "<") & @CRLF)
Next

output:

<fin>
<aa>aaa</aa>
<aa>bbb</aa>
<aa>ccc</aa>
<aa>ddd</aa>
</fin>
<fin key="test">
<aa>eee</aa>
<aa>fff</aa>
<aa>ggg</aa>
<aa>hhh</aa>
</fin>
<fin>
<aa>iii</aa>
<aa>jjj</aa>
<aa>kkk</aa>
<aa>lll</aa>
</fin>
<fin key="test">
<aa>mmm</aa>
<aa>nnn</aa>
</fin>

reading back the data would be a simple dom crawl.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...