Sign in to follow this  
Followers 0
shadowfiend

CSV UDF?

6 posts in this topic

I wonder if someone may help me.

I am pretty much a complete noob to programming but have managed to hack together some code to extract data from a proprietry database and put it into excel. The idea is to manipulate the data in Excel and get it back into the database.

I thought the CSV UDF by Ivan might be the way to go.

The function I need is _CSVRecordsGetFieldValue and here is my code:-

#include <CSVLib_V1.3.au3>

;variables

$path = "C:\Documents and Settings\User1\Desktop\New Folder (2)\AutoIT-scripts\autoit csv libs\trident-test.csv"
$pColumnNumber = 3
$pRowNumber = 3
$result = 0

$result = _CSVRecordsGetFieldValue($path, $pColumnNumber, $pRowNumber)

MsgBox(0, "result =", $result)

I can't seem to make it work and I get the folowing error

Line 935 (File "C:\autoit csv libs\CSVLib_V1.3.au3"):

If $pRowNumber <= $lColumn[0] Then

If $pRowNumber <= $lColumn^ ERROR

Error: Subscript used with non-Array variable.

Can someone tell me where I am going wrong?

I tried posting in Ivan`s csv udf thread but alas no reply.

Share this post


Link to post
Share on other sites



I wonder if someone may help me.

I am pretty much a complete noob to programming but have managed to hack together some code to extract data from a proprietry database and put it into excel. The idea is to manipulate the data in Excel and get it back into the database.

I thought the CSV UDF by Ivan might be the way to go.

The function I need is _CSVRecordsGetFieldValue and here is my code:-

#include <CSVLib_V1.3.au3>

;variables

$path = "C:\Documents and Settings\User1\Desktop\New Folder (2)\AutoIT-scripts\autoit csv libs\trident-test.csv"
$pColumnNumber = 3
$pRowNumber = 3
$result = 0

$result = _CSVRecordsGetFieldValue($path, $pColumnNumber, $pRowNumber)

MsgBox(0, "result =", $result)

I can't seem to make it work and I get the folowing error

Line 935 (File "C:\autoit csv libs\CSVLib_V1.3.au3"):

If $pRowNumber <= $lColumn[0] Then

If $pRowNumber <= $lColumn^ ERROR

Error: Subscript used with non-Array variable.

Can someone tell me where I am going wrong?

I tried posting in Ivan`s csv udf thread but alas no reply.

I can't see the function _CSVRecordsGetFieldValue in CSVLib_V1.3.au3, where is it?

Since line 935 of CSVLib_V1.3.au3 is "EndIf" I assume you are not using the UDF in the link you gave, or I am doing something wrong.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hi Martin, I am using the CSV UDF in the link (CSVLib_V1.3.au3) I have just downloaded it again and line 935 is:-

If $pRowNumber <= $lColumn[0] Then

You may want to double check.

Cheers.

Share this post


Link to post
Share on other sites

Hi Martin, I am using the CSV UDF in the link (CSVLib_V1.3.au3) I have just downloaded it again and line 935 is:-

If $pRowNumber <= $lColumn[0] Then

You may want to double check.

Cheers.

Thanks, I had got the wrong file.

It looks to me like there is an error in this function in the UDF

Func _CSVRecordsGetFieldValue($pRecords, $pColumnNumber, $pRowNumber, $pDelimiter = -1, $pEnclose = -1)
    If $pEnclose = -1 Then $pEnclose = '"'
    If $pDelimiter = -1 Then $pDelimiter = ','
    Local $lField = -1
    If StringLen($pDelimiter) = 0 Or StringLen($pEnclose) = 0 Or StringLen($pDelimiter) > 1 Or StringLen($pEnclose) > 1 Then
        SetError(1)
        Return 0
    EndIf
    Dim $lColumn
    $lColumn = _CSVRecordsGetColumn($pRecords, $pColumnNumber, $pDelimiter, $pEnclose)
    If @error <> 1 Then;[color="#FF0000"]LINE CHANGED<---------------this should be if @error <> 0 I think[/color]
        SetError(10 + @error)  ;[color="#FF0000"]LINE CHANGED= TEMP FIX<- then there should be something to decide what error was returned[/color]
        Return 0
    Else
        If $pRowNumber <= $lColumn[0] Then
            $lField = $lColumn[$pRowNumber]
        Else
            SetError(3)
            Return 0
        EndIf
    EndIf
    Return $lField
EndFunc   ;==>_CSVRecordsGetFieldValue

_CSVRecordsGetColumn is not returning an array so the line 935 should not be reached.

Maybe the problem is in your script, and the udf doesn't deal with it properly.

If IVAN sees your post he will be able to sort out any problem in the UDF, but meanwhile you could make the change I suggested and then check for errors reurned


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hi Martin, thanks for your reply. I tried your suggestion and it did get past the error message but the problem now is that I only get a return of 0. I have tried everything I can think of to get my script to work including a hand written CSV test file and always the return is 0. If only Ivan Perez were here...

:)

Share this post


Link to post
Share on other sites

Hi Martin, thanks for your reply. I tried your suggestion and it did get past the error message but the problem now is that I only get a return of 0. I have tried everything I can think of to get my script to work including a hand written CSV test file and always the return is 0. If only Ivan Perez were here...

:)

If the return is 0 then you need to know what the value of @error is to find out what is wrong. It should be something > 10 if the error is from CSVRecordsGetColumn with the change made.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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
Sign in to follow this  
Followers 0