Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

csv udf


  • Please log in to reply
32 replies to this topic

#1 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 23 December 2006 - 07:27 PM

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.
IVAN

Attached Files


Edited by ivan, 30 January 2007 - 07:28 PM.








#2 Dave in PNG

Dave in PNG

    Wayfarer

  • Active Members
  • Pip
  • 50 posts

Posted 24 December 2006 - 07:36 AM

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.

#3 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,199 posts

Posted 24 December 2006 - 07:55 AM

;===========================================================================================
; 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)

Posted Image

Clic The Pic!!!


#4 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 25 December 2006 - 10:14 PM

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 by ivan, 25 December 2006 - 10:48 PM.


#5 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,199 posts

Posted 27 December 2006 - 07:16 PM

be sure to check this one also...

AutoIt         
;=========================================================================================== ; 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)

Posted Image

Clic The Pic!!!


#6 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 28 December 2006 - 10:12 PM

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 by ivan, 28 December 2006 - 10:15 PM.


#7 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 28 December 2006 - 10:12 PM

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...

AutoIt         
;=========================================================================================== ; 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)



#8 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,199 posts

Posted 28 December 2006 - 10:28 PM

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)

Posted Image

Clic The Pic!!!


#9 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 28 December 2006 - 10:40 PM

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.

IVAN

You cant just post... testing is needed
8)


Edited by ivan, 28 December 2006 - 10:49 PM.


#10 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 29 December 2006 - 01:28 AM

Testing still needed.

Some fixes conducted and example file provided. See original post

Thanks for comments, suggestions or criticism to anyone interested.

Edited by ivan, 29 December 2006 - 01:29 AM.


#11 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 07 January 2007 - 09:26 PM

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 by ivan, 07 January 2007 - 09:27 PM.


#12 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 21 January 2007 - 07:19 PM

_CSVLib_V1.3.au3 is available. Major changes and corrections with respect to previous versions. Only minor bug in _CSVConvertLineBreak.

IVAN

#13 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 25 January 2007 - 06:55 PM

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

#14 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 30 January 2007 - 05:41 PM

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

#15 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,199 posts

Posted 30 January 2007 - 06:05 PM

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«mŠg¬Ê‹®±äž´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 by Valuater, 30 January 2007 - 06:06 PM.

Posted Image

Clic The Pic!!!


#16 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 30 January 2007 - 06:55 PM

@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

#17 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 28 February 2007 - 09:02 PM

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

#18 kheston

kheston

    Seeker

  • New Members
  • 2 posts

Posted 17 March 2007 - 07:47 AM

Works like a charm for me. Thanks!

#19 John C.

John C.

    Seeker

  • Active Members
  • 11 posts

Posted 27 March 2007 - 02:28 PM

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.
IVAN

Excellent coding.

#20 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 04 April 2007 - 06:35 PM

@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




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users