Sign in to follow this  
Followers 0
Terenz

For...next help with scheme

10 posts in this topic

#1 ·  Posted (edited)

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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

 

Share this post


Link to post
Share on other sites

Is more clear now?

Nope.

You posted the desired results, but you didn't give an example.

It's not enough detailled.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@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

 

Share this post


Link to post
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)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It require the last version of autoit, i'll download and if i have some problem i'll let you know, thanks ;)

Edited by Terenz

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

 

Share this post


Link to post
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)

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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.

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