gcue

add a new column after every record

12 posts in this topic

hello world =)

i am trying to add a new column after every record.  the method i am using is pretty dirty - writing to a tempfile and going through each line to add a new column after every last instance of a record.  i think it might be a better job for stringregexp?  

here is the string (basically a declaration of an array with unpredictable values)

$string = 'Local $flash[7][3]' & @CRLF & @CRLF

$string &= '$flash[0][0] = "AAAAAA1111-111"' & @CRLF
$string &= '$flash[0][1] = "AAAAAA1111*111"' & @CRLF
$string &= '$flash[0][2] = "AAAAAA1111^111"' & @CRLF

$string &= '$flash[1][0] = "BBBB!BB1111111"' & @CRLF
$string &= '$flash[1][1] = "BBB$BBB1111111"' & @CRLF
$string &= '$flash[1][2] = "BBBBB%B1111111"' & @CRLF

$string &= '$flash[2][0] = "CCCCCC222-2222"' & @CRLF
$string &= '$flash[2][1] = "CCC*CCC2222222"' & @CRLF
$string &= '$flash[2][2] = "CCCCCC22-22222"' & @CRLF

$string &= '$flash[3][0] = "DDDD-DDD333333"' & @CRLF
$string &= '$flash[3][1] = "DDD#DDDD333333"' & @CRLF
$string &= '$flash[3][2] = "DDDDD*DD333333"' & @CRLF

$string &= '$flash[4][0] = "EEEEEE$4444444"' & @CRLF
$string &= '$flash[4][1] = "EEEEEE#4444444"' & @CRLF
$string &= '$flash[4][2] = "EEEEEE!4444444"' & @CRLF

$string &= '$flash[5][0] = "FFFFFF-5555555"' & @CRLF
$string &= '$flash[5][1] = "FFFFFF;5555555"' & @CRLF
$string &= '$flash[5][2] = "FFFFFF*5555555"' & @CRLF

$string &= '$flash[6][0] = "GG%GGGGGG6666666"' & @CRLF
$string &= '$flash[6][1] = "GGG^GGGGG6666666"' & @CRLF
$string &= '$flash[6][2] = "GGGGGG*GG6666666"'

i am trying to add a third column ($flash[X][3] = "") for each record

so id like to be able to say replace X_TEXT with Y_TEXT

Y_TEXT would essentially be the [2] column line for every record PLUS the new line $flash[X][3] = ""

hope this makes sense.

thank you in advance!

Share this post


Link to post
Share on other sites



Use

ReDim $flash[7][4]

to add a column to the array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

right.. but im actually writing the text syntax to rebuild the array.. not actually rebuilding the array.. not sure if that makes sense?

Share this post


Link to post
Share on other sites

So you want to change the script source?

$string = 'Local $flash[7][3]' & @CRLF & @CRLF

$string &= '$flash[0][0] = "AAAAAA1111-111"' & @CRLF
$string &= '$flash[0][1] = "AAAAAA1111*111"' & @CRLF
$string &= '$flash[0][2] = "AAAAAA1111^111"' & @CRLF

to

$string = 'Local $flash[7][3]' & @CRLF & @CRLF

$string &= '$flash[0][0] = "AAAAAA1111-111"' & @CRLF
$string &= '$flash[0][1] = "AAAAAA1111*111"' & @CRLF
$string &= '$flash[0][2] = "AAAAAA1111^111"' & @CRLF
$string &= '$flash[0][3] = "AAAAAA1111/111"' & @CRLF ...

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

almost...

from this

$string = 'Local $flash[7][3]' & @CRLF & @CRLF

$string &= '$flash[0][0] = "AAAAAA1111-111"' & @CRLF
$string &= '$flash[0][1] = "AAAAAA1111*111"' & @CRLF
$string &= '$flash[0][2] = "AAAAAA1111^111"' & @CRLF

$string &= '$flash[1][0] = "BBBB!BB1111111"' & @CRLF
$string &= '$flash[1][1] = "BBB$BBB1111111"' & @CRLF
$string &= '$flash[1][2] = "BBBBB%B1111111"' & @CRLF

$string &= '$flash[2][0] = "CCCCCC222-2222"' & @CRLF
$string &= '$flash[2][1] = "CCC*CCC2222222"' & @CRLF
$string &= '$flash[2][2] = "CCCCCC22-22222"' & @CRLF

$string &= '$flash[3][0] = "DDDD-DDD333333"' & @CRLF
$string &= '$flash[3][1] = "DDD#DDDD333333"' & @CRLF
$string &= '$flash[3][2] = "DDDDD*DD333333"' & @CRLF

$string &= '$flash[4][0] = "EEEEEE$4444444"' & @CRLF
$string &= '$flash[4][1] = "EEEEEE#4444444"' & @CRLF
$string &= '$flash[4][2] = "EEEEEE!4444444"' & @CRLF

$string &= '$flash[5][0] = "FFFFFF-5555555"' & @CRLF
$string &= '$flash[5][1] = "FFFFFF;5555555"' & @CRLF
$string &= '$flash[5][2] = "FFFFFF*5555555"' & @CRLF

$string &= '$flash[6][0] = "GG%GGGGGG6666666"' & @CRLF
$string &= '$flash[6][1] = "GGG^GGGGG6666666"' & @CRLF
$string &= '$flash[6][2] = "GGGGGG*GG6666666"'

to this

$string = 'Local $flash[7][3]' & @CRLF & @CRLF

$string &= '$flash[0][0] = "AAAAAA1111-111"' & @CRLF
$string &= '$flash[0][1] = "AAAAAA1111*111"' & @CRLF
$string &= '$flash[0][2] = "AAAAAA1111^111"' & @CRLF
$string &= '$flash[0][3] = ""' & @CRLF

$string &= '$flash[1][0] = "BBBB!BB1111111"' & @CRLF
$string &= '$flash[1][1] = "BBB$BBB1111111"' & @CRLF
$string &= '$flash[1][2] = "BBBBB%B1111111"' & @CRLF
$string &= '$flash[1][3] = ""' & @CRLF

$string &= '$flash[2][0] = "CCCCCC222-2222"' & @CRLF
$string &= '$flash[2][1] = "CCC*CCC2222222"' & @CRLF
$string &= '$flash[2][2] = "CCCCCC22-22222"' & @CRLF
$string &= '$flash[2][3] = ""' & @CRLF

$string &= '$flash[3][0] = "DDDD-DDD333333"' & @CRLF
$string &= '$flash[3][1] = "DDD#DDDD333333"' & @CRLF
$string &= '$flash[3][2] = "DDDDD*DD333333"' & @CRLF
$string &= '$flash[3][3] = ""' & @CRLF

$string &= '$flash[4][0] = "EEEEEE$4444444"' & @CRLF
$string &= '$flash[4][1] = "EEEEEE#4444444"' & @CRLF
$string &= '$flash[4][2] = "EEEEEE!4444444"' & @CRLF
$string &= '$flash[4][3] = ""' & @CRLF

$string &= '$flash[5][0] = "FFFFFF-5555555"' & @CRLF
$string &= '$flash[5][1] = "FFFFFF;5555555"' & @CRLF
$string &= '$flash[5][2] = "FFFFFF*5555555"' & @CRLF
$string &= '$flash[5][3] = ""' & @CRLF

$string &= '$flash[6][0] = "GG%GGGGGG6666666"' & @CRLF
$string &= '$flash[6][1] = "GGG^GGGGG6666666"' & @CRLF
$string &= '$flash[6][2] = "GGGGGG*GG6666666"' & @CRLF
$string &= '$flash[6][3] = ""'

thanks for your help!

Share this post


Link to post
Share on other sites

I still don't fully understand your problem.
Can't you just copy the changed lines from your last post to your script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

actually im working on a script that modifies existing arrays.. so in case you wanted to add/delete a column/record to your existing array you can do so without losing your existing values.  

Share this post


Link to post
Share on other sites

So you write a script to modify the source code of another script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Have you tried using _ArrayColInsert or _ArrayColDelete?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

actually its meant for hard coded arrays.. where values to arrays are set within the script.  so its for cases where those arrays need modifying..

Share this post


Link to post
Share on other sites

Hard coded values ... BBRRR.
Wouldn't it make more sense to store those values in a file?
Proof of concept:
Store the array in a CSV and retrieve it when needed.
 

#include <File.au3>
Local $flash[7][3]

$flash[0][0] = "AAAAAA1111-111"
$flash[0][1] = "AAAAAA1111*111"
$flash[0][2] = "AAAAAA1111^111"

$flash[1][0] = "BBBB!BB1111111"
$flash[1][1] = "BBB$BBB1111111"
$flash[1][2] = "BBBBB%B1111111"

$flash[2][0] = "CCCCCC222-2222"
$flash[2][1] = "CCC*CCC2222222"
$flash[2][2] = "CCCCCC22-22222"

$flash[3][0] = "DDDD-DDD333333"
$flash[3][1] = "DDD#DDDD333333"
$flash[3][2] = "DDDDD*DD333333"

$flash[4][0] = "EEEEEE$4444444"
$flash[4][1] = "EEEEEE#4444444"
$flash[4][2] = "EEEEEE!4444444"

$flash[5][0] = "FFFFFF-5555555"
$flash[5][1] = "FFFFFF;5555555"
$flash[5][2] = "FFFFFF*5555555"

$flash[6][0] = "GG%GGGGGG6666666"
$flash[6][1] = "GGG^GGGGG6666666"
$flash[6][2] = "GGGGGG*GG6666666"
_ArrayDisplay($flash)
_FileWriteFromArray("C:\temp\test.csv", $flash, 0)
Global $aArray
_FileReadToArray("C:\temp\test.csv", $aArray, $FRTA_NOCOUNT, "|")
_ArrayDisplay($aArray)

This makes changes much easier.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hard coded values ... BBRRR.
Wouldn't it make more sense to store those values in a file?
Proof of concept:
Store the array in a CSV and retrieve it when needed.
 

#include <File.au3>
Local $flash[7][3]

$flash[0][0] = "AAAAAA1111-111"
$flash[0][1] = "AAAAAA1111*111"
$flash[0][2] = "AAAAAA1111^111"

$flash[1][0] = "BBBB!BB1111111"
$flash[1][1] = "BBB$BBB1111111"
$flash[1][2] = "BBBBB%B1111111"

$flash[2][0] = "CCCCCC222-2222"
$flash[2][1] = "CCC*CCC2222222"
$flash[2][2] = "CCCCCC22-22222"

$flash[3][0] = "DDDD-DDD333333"
$flash[3][1] = "DDD#DDDD333333"
$flash[3][2] = "DDDDD*DD333333"

$flash[4][0] = "EEEEEE$4444444"
$flash[4][1] = "EEEEEE#4444444"
$flash[4][2] = "EEEEEE!4444444"

$flash[5][0] = "FFFFFF-5555555"
$flash[5][1] = "FFFFFF;5555555"
$flash[5][2] = "FFFFFF*5555555"

$flash[6][0] = "GG%GGGGGG6666666"
$flash[6][1] = "GGG^GGGGG6666666"
$flash[6][2] = "GGGGGG*GG6666666"
_ArrayDisplay($flash)
_FileWriteFromArray("C:\temp\test.csv", $flash, 0)
Global $aArray
_FileReadToArray("C:\temp\test.csv", $aArray, $FRTA_NOCOUNT, "|")
_ArrayDisplay($aArray)

This makes changes much easier.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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