ivan Posted December 23, 2006 Share Posted December 23, 2006 (edited) Here's a udf to handle csv files. I'm releasing the latest version _CSVLib_V1.3.au3, with nearly 10 new functions, all functions have been thoroughly reviewed and tested. I found a minor bug in _CSVConvertLineBreak, and I'll fix it soon. The examples do not work with version 1.3, but a single file will be made available in the next revision in mid february. I'm cought up in the middle of an install kit that I was hired for, so I really can't commit myself earlier than that. All versions prior to 1.3 and their respective examples will be removed in that revision. I'd really appreciate any help testing these functions or comments or ideas. Thanks in advance. IVANCSVExample.au3_CSVLib.au3_CSVLib_V1.0.au3CSVExampleFile_V1.au3_CSVLib_V1.1.au3CSVGuiExample_V1.1.au3_CSVLib_V1.3.au3 Edited January 30, 2007 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Dave in PNG Posted December 24, 2006 Share Posted December 24, 2006 Great coding. I tried to trip it up using some combinations of things that I remember tripping Excel up. The parts I tried worked perfectly. I'll be able to use this code immediately. Thanks. Link to comment Share on other sites More sharing options...
Valuater Posted December 24, 2006 Share Posted December 24, 2006 ;=========================================================================================== ; Function List: ; _CSVGetRecords: Retreives the contents of a csv file to a 1 Dim Array. ; _CSVGetColumn: Retreives the column of a csv file to a 1 Dim Array. ; _CSVRecordToFields: Converts a given Record (csv line) to a 1 Dim array of Fields ; _CSVStringToField: Converts a text string to csv format to store in a single field. ; _CSVFieldToString: Converts the content of a single csv field to a text string. ; Author: IVAN PEREZ ;=========================================================================================== i dont see this function in the list above ;=========================================================================================== ; Function Name: _CSVGetField ............ ???? 8) Link to comment Share on other sites More sharing options...
ivan Posted December 25, 2006 Author Share Posted December 25, 2006 (edited) Thanks for the encouragement guys. I've got about 10 changes to the previous scripts including functions that specifically convert delimiters and enclose characters, as well as writing csv. I'll make them available as soon as I get back to the office in early January. @Valuater: Thanks. I added _CSVGetField to the list and updated the original post. However, those are likely to be changed as I'll be including CSV write functions as well as delimiter and enclose conversions. I'll also improve the example and provide some documentation on the processes used. It's an honor that you've taken a look at my script. I just lost my number of downloads. Shame. Regards and merry crhistmas. IVAN Edited December 25, 2006 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Valuater Posted December 27, 2006 Share Posted December 27, 2006 be sure to check this one also... ;=========================================================================================== ; Function Name: _CSVFieldToString ; Description: Converts the content of a single csv field to a text string. ; Syntax: _CSVFieldToString($pRawField [,$pEnclose] [,$pDelimiter]) ; Parameter(s): $pRawField - Raw csv string. ; $pDelimiter - Use -1 for default field separator char ','. ; $pEnclose - Use -1 for default quote char '"'. ; Requirement(s): None ; Return Value(s): On Success - 1 Dim $lRecords array ; On Failure - Errors not defined yet ; Warning: Not tested with Delimiters other than the defaults. ; Date: 20/12/06 ; Author: IVAN PEREZ ;=========================================================================================== Func _CSVFieldToString($pRawField, $pDelimiter, $pEnclose) Local $lStr = $pRawField ; strip StartEnclose and EndEnclose If StringLeft($lStr, 1) = $pEnclose And StringRight($lStr, 1) = $pEnclose Then $lStr = StringRight($lStr, StringLen($lStr) - 1) $lStr = StringLeft($lStr, StringLen($lStr) - 1) $lStr = StringReplace($lStr, $pEnclose & $pEnclose, $pEnclose) EndIf Return $lStr EndFunc ;==>_CSVFieldToString where... $pDelimiter - Use -1 for default field separator char ','. is not used within the function .... keep up the good work 8) Link to comment Share on other sites More sharing options...
ivan Posted December 28, 2006 Author Share Posted December 28, 2006 (edited) New version of the csv udf available. See first post. Help needed for testing. I'm away and have little access to a pc with autoit and scite. Thanks IVAN Edited December 28, 2006 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted December 28, 2006 Author Share Posted December 28, 2006 Thanks again Valuater. I've implemented your suggestion in _CSVLib_V1.0.au3. This modified script with about a dozen new functions ought to work... Some functions have not even been tested, but they rely on the same principle. I'd be really grateful if you or anyone else can give me a hand testing them, as I'm away and have little time to look at the script. IVAN be sure to check this one also... ;=========================================================================================== ; Function Name: _CSVFieldToString ; Description: Converts the content of a single csv field to a text string. ; Syntax: _CSVFieldToString($pRawField [,$pEnclose] [,$pDelimiter]) ; Parameter(s): $pRawField - Raw csv string. ; $pDelimiter - Use -1 for default field separator char ','. ; $pEnclose - Use -1 for default quote char '"'. ; Requirement(s): None ; Return Value(s): On Success - 1 Dim $lRecords array ; On Failure - Errors not defined yet ; Warning: Not tested with Delimiters other than the defaults. ; Date: 20/12/06 ; Author: IVAN PEREZ ;=========================================================================================== Func _CSVFieldToString($pRawField, $pDelimiter, $pEnclose) Local $lStr = $pRawField ; strip StartEnclose and EndEnclose If StringLeft($lStr, 1) = $pEnclose And StringRight($lStr, 1) = $pEnclose Then $lStr = StringRight($lStr, StringLen($lStr) - 1) $lStr = StringLeft($lStr, StringLen($lStr) - 1) $lStr = StringReplace($lStr, $pEnclose & $pEnclose, $pEnclose) EndIf Return $lStr EndFunc ;==>_CSVFieldToString where... $pDelimiter - Use -1 for default field separator char ','. is not used within the function .... keep up the good work 8) Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Valuater Posted December 28, 2006 Share Posted December 28, 2006 You cant just post... testing is needed +> Starting AutoIt3Wrapper v.1.7.4 >Running AU3Check (1.54.5.0) params: from:C:\Program Files\AutoIt3\beta C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(582,92) : ERROR: _CSVFieldToString() called with wrong number of args. $lFields[uBound($lFields) - 1]= _CSVFieldToString($lRecord[$j], $pDelimiter, $pEnclose) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(520,51) : REF: definition of _CSVFieldToString(). Func _CSVFieldToString($pRawField, $pEnclose = -1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(596,64) : ERROR: _CSVFieldToString() called with wrong number of args. $lField = _CSVFieldToString($pConvert, $pDelimiter, $pEnclose) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(520,51) : REF: definition of _CSVFieldToString(). Func _CSVFieldToString($pRawField, $pEnclose = -1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(649,92) : ERROR: _CSVFieldToString() called with wrong number of args. $lFields[uBound($lFields) - 1] = _CSVFieldToString($lRecord[$j], $pDelimiter, $pEnclose) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(520,51) : REF: definition of _CSVFieldToString(). Func _CSVFieldToString($pRawField, $pEnclose = -1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(663,64) : ERROR: _CSVFieldToString() called with wrong number of args. $lField = _CSVFieldToString($pConvert, $pDelimiter, $pEnclose) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3(520,51) : REF: definition of _CSVFieldToString(). Func _CSVFieldToString($pRawField, $pEnclose = -1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\test1212_old1_old2_old1_old3.au3 - 4 error(s), 0 warning(s) !>AU3Check ended.rc:2 >Exit code: 0 Time: 0.518 8) Link to comment Share on other sites More sharing options...
ivan Posted December 28, 2006 Author Share Posted December 28, 2006 (edited) That was quick.When I deleted the unecessary $pDelimiter in _CSVFieldToString, I forgot to feed the changes into the funcs that called it.It's taken care of and the correction has been uploaded in the original post.IVANYou cant just post... testing is needed8) Edited December 28, 2006 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted December 29, 2006 Author Share Posted December 29, 2006 (edited) Testing still needed. Some fixes conducted and example file provided. See original post Thanks for comments, suggestions or criticism to anyone interested. Edited December 29, 2006 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted January 7, 2007 Author Share Posted January 7, 2007 (edited) Fixes on conversion functions in _CSVLib_V1.1 and new gui example in CSVGuiExample_V1.1 available in first post. New example should prove that any 2 chars can be used as delimiter and enclose respectively. Please provide feedback. IVAN Edited January 7, 2007 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted January 21, 2007 Author Share Posted January 21, 2007 _CSVLib_V1.3.au3 is available. Major changes and corrections with respect to previous versions. Only minor bug in _CSVConvertLineBreak. IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted January 25, 2007 Author Share Posted January 25, 2007 Hi guys. I'll clean up in mid february the older versions as soon as i fix the bug in _CSVConvertLineBreak. I will only leave the current version and a couple of examples. } As noted in my previous posts, feedback would greatly be appreciated. IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted January 30, 2007 Author Share Posted January 30, 2007 I recently got a PM with a question about which version matches which example, so I apologize for the potential confusion. You should be able to tell from the include line on the example and download the library required. Version 1.3 does not have an associated example file, and there were significant changes to existing functions, not only to names, but the way they work, namely using ByRef in function parameters so as to speed up processes and reduce the amount of coding required to accomplish a task. I will make an example file for version 1.3 in mid february, as soon as I finish a job I'm doing, and there's a small bug in line the break conversion function which I need to fix. Once that is done, I WILL REMOVE ALL PREVIOUS VERSIONS AND LEAVE A SINGLE VERSION, BASED ON 1.3. 2 Reasons for this, 1) I'm running out of space 2) I don't want to create confusion Regards IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Valuater Posted January 30, 2007 Share Posted January 30, 2007 (edited) Looks nice... 1 Yes, an example would help and removal of the older versions is a must 2 I noticed an error return in an incorrect order (7) If Not _CSVColumnAppend($lRecords, $pColumn, $pDelimiter, $pEnclose, $pMode) Then SetError(7, @error)*******************Here** Return 0 EndIf ; open file in overwrite mode $lCSVFileHandle = FileOpen($pFullPath, 2) If $lCSVFileHandle = -1 Then FileClose($lCSVFileHandle) SetError(5) Return 0 EndIf For $i = 1 To UBound($lRecords) - 1 Step 1 $lCheckWrite = FileWriteLine($lCSVFileHandle, $lRecords[$i]) If $lCheckWrite = 0 Then FileClose($lCSVFileHandle) SetError(6) Return 0 EndIf oÝ÷ Ûr'¢Øy«mg¬Ê®±ä´J뢽^®º+ëf¢ËeÊ;¬µ'ºè¯R-)äÛ ¢m¡©e¶Ü¢Z+£M4ÓM,¥©ì·)^oÝ÷ Ø*.ÖÞjëh×6 If Not _CSVColumnAppend($lRecords, $pColumn, $pDelimiter, $pEnclose, $pMode) Then Return SetError(7, @error, 0) Less code also! ..... Just some thoughts I notice all the views and downloads but nobody seems to post any thoughts ( same with my threads ) lol 8) Edited January 30, 2007 by Valuater Link to comment Share on other sites More sharing options...
ivan Posted January 30, 2007 Author Share Posted January 30, 2007 @Valuater: I'll certainly add the error setting/tracking as one of the top todos in my next revision in mid february. Whenever I use @error in SetError it's mainly for back tracking purposes, so I'll strictly limit to that. I guess that could make it easier to read. Why didn't I think of Return SetError(7, @error, 0) ??? I think it's great! I was also surprised to see that, except from the first reply and your greatly appreciated comments, no one else has posted anything. I believe that all the files are creating confusion, and now with the upgrades in version 1.3, confusion is likely to be even greater. Hopefully there'll be more comments once people see it working in a more real example. I'm working on one that uses the driverquery command in cmd to output a csv file. Then I try to illustrate various functions with the driver query results. I still have some work to do on it, but so far it looks promising. Thanks, IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted February 28, 2007 Author Share Posted February 28, 2007 Sorry for the delay, and it's gonna take longer. My daughter cought pneumonia over carnival and was hospitalized. She left the intensive care unit yesterday (over 4 days of traumatic experience for a 2 year old), so don't expect me around for a while. IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
kheston Posted March 17, 2007 Share Posted March 17, 2007 Works like a charm for me. Thanks! Link to comment Share on other sites More sharing options...
John C. Posted March 27, 2007 Share Posted March 27, 2007 Here's a udf to handle csv files. I'm releasing the latest version _CSVLib_V1.3.au3, with nearly 10 new functions, all functions have been thoroughly reviewed and tested. I found a minor bug in _CSVConvertLineBreak, and I'll fix it soon.The examples do not work with version 1.3, but a single file will be made available in the next revision in mid february. I'm cought up in the middle of an install kit that I was hired for, so I really can't commit myself earlier than that.All versions prior to 1.3 and their respective examples will be removed in that revision.I'd really appreciate any help testing these functions or comments or ideas.Thanks in advance.IVANExcellent coding. Link to comment Share on other sites More sharing options...
ivan Posted April 4, 2007 Author Share Posted April 4, 2007 @John C.: Thanks. Today's the first time I've had to llok at this post. I hope to have an upgrade implementing some suggestions and cleaning a bug in the line break conversion function in v1.3. IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 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