AutoHotkey Community

It is currently May 27th, 2012, 6:14 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: July 4th, 2010, 7:46 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
nnah wrote:
How do I adjust the code below to replace the data in File A column 2 with the data in File B Column 2?
Commented the code above, I don't understand your question as the script above does exactly that. It replaces the data in the 2nd column (b) in file A with the data from file b.

Edit: and you COULD use TF, see http://www.autohotkey.com/forum/viewtop ... 868#366868

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: File manipulation
PostPosted: November 9th, 2010, 5:59 pm 
Offline

Joined: August 28th, 2009, 11:17 am
Posts: 599
Location: Brighton, UK
nnah wrote:
Can you explain this line of code? StringReplace, ColB, ColB, `r`n, |, All


Replace all instances of | with `r`n (linebreak)

_________________
With mixed feelings I am stepping down from all moderation responsibilities: http://www.autohotkey.com/forum/viewtopic.php?t=82906


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2010, 9:57 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
how can i load a column into a DDL control if the one of the item in that column has a comma as part of it?

Code:
GetColumn:=CSV_ReadCol(CSV_Identifier, 2)
...
Gui, +Delimiter`,
Gui, Add, DropDownList, AltSubmit vDDL1 gDDL1, %GetColumn%
Gui, Show


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2010, 8:28 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Bug report
CSV_MatchCellRow has a bug in it, see post and fix here
http://www.autohotkey.com/forum/viewtop ... 667#400667

Quote:
- Look up the CSV_MatchCellRow function
- in that function there is a line
Code:
IfEqual, CurrentRow, %SearchText%

- change it to
Code:
IfEqual, CurrentString, %SearchText%

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2010, 3:29 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
@kdoske:

Suggestion for new function
see "Convert CSV into HTML table"
http://www.autohotkey.com/forum/viewtopic.php?p=401213
for the idea (don't use the posted code there of course)

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2011, 6:38 pm 
Can anyone tell me if this lib has the ability to read a semicolon delimited text file and rearrange out-of-order rows?

The file should look like this:
A;B;C;D;E;F;G

Some rows look like this:
A;F;G;E;C;B;D

Is it possible to identify those rows and put them in the expected order?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2011, 10:26 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
You would read / load your file like so
Code:
CSV_Load("file.txt", Data, ";")

now each "cell" (row,column) is stored in memory which you can manipulate. Using a loop you can create a new CSV file (text file) making sure each cell is in the correct place

How do you know which lines are "bad"?

Pseudocode:

- Loop, NumberOfRows (see CSV Lib)
- If ROW = OK
then FILEAPPEND CELLS FROM ROW AS IS
ELSE
FILEAPPEND CELLS IN CORRECT ORDER
- done
Not saying it is the most efficient method, but if you can identify the BAD lines it isn't that complicated.

Edit: seems solved here http://www.autohotkey.com/forum/topic67817.html

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject: some verifications
PostPosted: January 27th, 2011, 2:00 pm 
I was working with an old csv lib version and found some problems with some functions...
Could be good make some verifications like this ...
Code:
CSV_ReadRow(RowNumber)
  {
   Local RowData:=""
   if ( RowNumber<1 or RowNumber>CSV_TotalRows) {
   ErrorLevel=1
        return ""
        }
   Loop, %CSV_TotalCols%
     {
       RowData .= CSV_Row%RowNumber%_Col%A_Index%
      If A_Index <> %CSV_TotalCols%
         RowData .= CSV_Delimiter
     }
     ErrorLevel=0
     Return %RowData%
  }


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2011, 5:27 pm 
Offline

Joined: November 18th, 2010, 6:39 pm
Posts: 10
Just taking some time out to say thanks for this library. As a noob, it's been super useful and I have already used it a number of times. Great job!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2011, 8:33 pm 
Duplicity wrote:
Just taking some time out to say thanks for this library. As a noob, it's been super useful and I have already used it a number of times. Great job!


Same here, many thanks! It seems to find itself of good use in a number of my scripts as well.


Report this post
Top
  
Reply with quote  
PostPosted: June 20th, 2011, 8:55 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Bug report
Test script to replicate the problem. If someone could confirm that would be helpful. If you are reading multiple rows or columns in a row using CSV_ReadRow and/or CSV_ReadCol it "appends" your previous column or row to what is returned from the function, so you send up with multiple rows which is not what you expect.

Bugfixes for those who have this lib below the test code, add two lines see comments

Code:
f=testing.csv
csv= ; create test data file
(
1,2,3
4,5,6
7,8,9
0,a,b
c,d,e
)
FileDelete, %f%
FileAppend, %csv%, %f%
CSV_Load("testing.csv", "data") ; read testing.csv

Loop, % CSV_TotalRows("data")
   MsgBox % CSV_ReadRow("data", A_Index)

Loop, % CSV_TotalCols("data")
   MsgBox % CSV_ReadCol("data", A_Index)
   
/* Bug fixes

CSV_ReadRow(CSV_Identifier, RowNumber)
{
  Local CellData
  CurrentCSV_TotalCols := %CSV_Identifier%CSV_TotalCols
   RowData= ; add this line
  Loop, %CurrentCSV_TotalCols%
  {
    RowData .= %CSV_Identifier%CSV_Row%RowNumber%_Col%A_Index%
    If A_Index <> %CurrentCSV_TotalCols%
      RowData .= "`,"
  }
  Return %RowData%
}

CSV_ReadCol(CSV_Identifier, ColNumber)
{
  Local CellData
  CurrentCSV_TotalRows := %CSV_Identifier%CSV_TotalRows   
  ColData= ; add this line
  Loop, %CurrentCSV_TotalRows%
  {
    ColData .= %CSV_Identifier%CSV_Row%A_Index%_Col%ColNumber%
    If A_Index <> %CurrentCSV_TotalRows%
      ColData .= "`,"
  }
  Return %ColData%
}


Edit

Bug in CSV_LVSave:
Format4CSV isn't used while exporting Listview data, quick fix:

In CSV_LVSave change line
Code:
FullRow .= CellData

to
Code:
FullRow .= Format4CSV(CellData)


Further improvement would be to skip empty rows although should probably be a parameter.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Last edited by SoLong&Thx4AllTheFish on June 21st, 2011, 7:59 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2011, 9:57 pm 
Offline

Joined: November 22nd, 2010, 5:10 pm
Posts: 9
Location: Indianapolis, Indiana
Confirmed, I experienced this problem too but forgot to suggest this same bugfix. I believe there is also another bug in a function that uses a comma delimiter instead of the user's specified delimiter. I'll see if I can find this one again.

*Edit: There wasn't an actual bug, just a small annoyance. When I use CSV_ReadRow I expected it to feed me the same delimiter I specified upon loading the file instead of a comma.

I made the delimeter global by adding this (green text) to CSV_Load:
Code:
CSV_Load(FileName, CSV_Identifier="", Delimiter="`,")
{
  Global
  _Delimiter := Delimiter

...


then I changed "`," to _Delimiter for the functions CSV_ReadRow and CSV_ReadCol.


Last edited by QuantumSingular on June 21st, 2011, 9:06 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2011, 8:02 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
See my previous bug post above, found another one in CSV_LVSave.

(I'm finding these bugs because I'm developing a CSV quick filter/search app that uses the Listview functions form this lib for import/export, will post it as a separate script when completed)

Edit:
See CSV Quick Filter - CSVQF
http://www.autohotkey.com/forum/viewtopic.php?t=73344

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Encapsulation CSV_Save
PostPosted: October 25th, 2011, 11:29 am 
For the creators of this script.

I had trouble with CSV_Save dropping the encapsulation from the CSV File. Thus it would then en up with only 1 column as returnDSVarray would only load 1 column next time without quotes

I Ammended CSV save to the following
Code:
Loop, %CurrentCSV_TotalCols%
   {
      Col := A_Index
     EntireFile .= """"   ;added this line
      EntireFile .= Format4CSV(%CSV_Identifier%CSV_Row%Row%_Col%Col%)
     EntireFile .= """"   ;added this line
      If (Col <> %CSV_Identifier%CSV_TotalCols)
         EntireFile .= %CSV_Identifier%CSV_Delimiter
   }


I am not sure why my setup is the first to have this problem as this is an old thread.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2012, 7:55 pm 
When I try :
teste.csv before script
1111,1111

CSV_Load("teste.csv",AA,";")
CSV_ModifyCell(AA,7777,1,1)
CSV_ModifyCell(AA,7777,1,2)
CSV_Save("teste.csv",AA,1)

teste.csv output
7777

so ever time it is delete the last row, also if I want change just first row the last will be deleted !!!
someone can help me ?
thx


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Google Feedfetcher, JamixZol, rbrtryn, Stigg, Yahoo [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group