charon Posted January 24, 2014 Share Posted January 24, 2014 I am trying to inert a new value into an existing array I have an array that looks like this before I change it: Row|Col 0 [0]|10 [1]|10 [2]|JourneyFrontiersJourney-After The Fall.mp3 [3]|JourneyFrontiersJourney-Ask the Lonely.mp3 [4]|JourneyGreatest_HitsJourney-Any Way You Want It.mp3 [5]|JourneyGreatest_HitsJourney-Dont Stop Believin.mp3 [6]|QueensrycheEmpireQueensryche-01-Best I Can.mp3 [7]|QueensrycheEmpireQueensryche-02-The Thin Line.mp3 I am trying to make it look like this: The insert is only when the artist changes and then I insert: new channel2 broadcast enabled loop Row|Col 0 [0]|10 [1]|10 [2]|setup channel1 input "C:atestJourneyFrontiersJourney-After The Fall.mp3" [3]|setup channel1 input "C:atestJourneyFrontiersJourney-Ask the Lonely.mp3" [4]|setup channel1 input "C:atestJourneyGreatest_HitsJourney-Any Way You Want It.mp3" [5]|new channel2 broadcast enabled loop [6]|setup channel2 input "C:atestQueensrycheEmpireQueensryche-02-The Thin Line.mp3" [7]|setup channel2 input "C:atestQueensrycheEmpireQueensryche-03-Jet City Woman.mp3 Here is what I get: A big mess Row|Col 0 [0]|10 [1]|10 [2]|setup channel1 input "C:atestJourneyFrontiersJourney-After The Fall.mp3" [3]|setup channel1 input "C:atestJourneyFrontiersJourney-Ask the Lonely.mp3" [4]|setup channel1 input "C:atestJourneyGreatest_HitsJourney-Any Way You Want It.mp3" [5]|new channel2 broadcast enabled loop [6]|new channel3 broadcast enabled loop [7]|new channel4 broadcast enabled loop [8]|new channel5 broadcast enabled loop [9]|new channel6 broadcast enabled loop [10]|new channel7 broadcast enabled loop [11]|setup channel1 input "C:atestJourneyGreatest_HitsJourney-Dont Stop Believin.mp3" [12]|setup channel7 input "C:atestsetup channel6 input "C:atestsetup channel5 input "C:atestsetup channel4 input "C:atestsetup channel3 input "C:atestsetup channel2 input "C:atestQueensrycheEmpireQueensryche-01-Best I Can.mp3 [13]|QueensrycheEmpireQueensryche-02-The Thin Line.mp3 [14]|QueensrycheEmpireQueensryche-03-Jet City Woman.mp3 Here is my loop: $iPosition = StringInStr($aArray[2], "\") $sString[0] = StringLeft($aArray[2], $iPosition -1) ; Retrieve 5 characters from the left of the string. $sString[1] = StringLeft($aArray[2], $iPosition -1) ;MsgBox(0, "", "string: " & $sString[0]) For $i = 2 To $aArray[0] +1 $iPosition = StringInStr($aArray[$i], "\") $sString[1] = StringLeft($aArray[$i], $iPosition -1) ; Retrieve 5 characters from the left of the string. If $sString[0] <> $sString[1] Then ;if artist doesn't match then we increment channel and insert new value at position $i - 1 ;MsgBox(0, "", "change found" & @CR & "string[0]= " & $sString[0] & @CR & "string[1]: " & $sString[1] & @CR & "loop i is: " & $i) $sString[0] = $sString[1] $channel = $channel +1 ;MsgBox(0, "", "after= " & @CR & "string[0]= " & $sString[0] & @CR & "string[1]: " & $sString[1] & @CR & "loop i is: " & $i) $sInsertString = 'setup channel' & $channel & ' input "' & $dir & '\' $aArray[$i] = _StringInsert($aArray[$i], $sInsertString, 0) ;insert new channel $newChannel = "new channel" & $channel & " broadcast enabled loop" _ArrayInsert($aArray, $i -1, $newChannel) Else $aArray[$i] = _StringInsert ( $aArray[$i], $sInsertString, 0) $aArray[$i] = $aArray[$i] & $sInsertString2 EndIf Next Link to comment Share on other sites More sharing options...
JohnOne Posted January 24, 2014 Share Posted January 24, 2014 Have you raed and tried the example for _ArrayInsert? You should. 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 More sharing options...
jdelaney Posted January 24, 2014 Share Posted January 24, 2014 (edited) With arrayinsert: expandcollapse popup#include <array.au3> $directory = "C:\" Local $aArray[8] $aArray[0]=10 $aArray[1]=10 $aArray[2]="Journey\Frontiers\Journey-After The Fall.mp3" $aArray[3]="Journey\Frontiers\Journey-Ask the Lonely.mp3" $aArray[4]="Journey\Greatest_Hits\Journey-Any Way You Want It.mp3" $aArray[5]="Journey\Greatest_Hits\Journey-Dont Stop Believin.mp3" $aArray[6]="Queensryche\Empire\Queensryche-01-Best I Can.mp3" $aArray[7]="Queensryche\Empire\Queensryche-02-The Thin Line.mp3" $bAddNewChannel1 = False ; make False if you don't want "new chanel1 broadcast enabled loop" $iUbound = UBound($aArray)-1 $iCurrent = 0 $sLast = "" $i = 2 While True $sCurrent = StringRegExpReplace($aArray[$i],"(\\.*)","") If $sCurrent <> $sLast Then $sLast = $sCurrent $iCurrent+=1 $aArray[$i] = "setup channel" & $iCurrent & " input " & $directory & $aArray[$i] If ($iCurrent=1 And $bAddNewChannel1) Or $iCurrent>1 Then _ArrayInsert($aArray,$i,"new Channel" & $iCurrent & " broadcast enabled loop") $iUbound+=1 $i+=1 EndIf Else $aArray[$i] = "setup channel" & $iCurrent & " input " & $directory & $aArray[$i] EndIf $i+=1 If $i > $iUbound Then ExitLoop WEnd _ArrayDisplay($aArray) Edited January 24, 2014 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 More sharing options...
Moderators Solution Melba23 Posted January 24, 2014 Moderators Solution Share Posted January 24, 2014 charon,Try this: expandcollapse popup#include <Array.au3> Global $aList[] = [10, _ 10, _ "Journey\Frontiers\Journey-After The Fall.mp3", _ "Journey\Frontiers\Journey-Ask the Lonely.mp3", _ "Journey\Greatest_Hits\Journey-Any Way You Want It.mp3", _ "Journey\Greatest_Hits\Journey-Dont Stop Believin.mp3", _ "Queensryche\Empire\Queensryche-01-Best I Can.mp3", _ "Queensryche\Empire\Queensryche-02-The Thin Line.mp3"] _ArrayDisplay($aList, "Original", Default, 8) $iLine = -1 $sCurrent_Band = "" $iChannel = 0 $sString_1 = 'setup channel' $sString_2 = 'input "C:\atest\' While 1 ; Next line and check still within array $iLine += 1 If $iLine = UBound($aList, $UBOUND_ROWS) Then ExitLoop ; Skip leading lines with numbers If Int($aList[$iLine]) <> 0 Then ContinueLoop ; Split line to get band $aSplit = StringSplit($aList[$iLine], "\") If $aSplit[1] <> $sCurrent_Band Then ; Increase channel $iChannel += 1 If $iChannel > 1 Then ; Insert line for channel if greater then 1 _ArrayInsert($aList, $iLine, "new channel" & $iChannel & " broadcast enabled loop") ; Skip that line $iLine += 1 EndIf ; Reset current band $sCurrent_Band = $aSplit[1] EndIf ; Add text to line $aList[$iLine] = $sString_1 & $iChannel & $sString_2 & $aList[$iLine] & '"' WEnd _ArrayDisplay($aList, "Amended", Default, 8)Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jdelaney Posted January 24, 2014 Share Posted January 24, 2014 "Great minds..." ^^ I'm modest, too! (ha) 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 More sharing options...
Moderators Melba23 Posted January 24, 2014 Moderators Share Posted January 24, 2014 jdelaney,And I really did not peek at yours before posting. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
charon Posted January 24, 2014 Author Share Posted January 24, 2014 Thanks Melba23 and everyone for all your help. I only had to change a few lines of code to get it working and I understand the code you used. The while loop and StringSplit worked a lot better. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now