Not sure why you're going to so much effort during script development and debugging - SetConsole(hide) and MessageBox(). Yikes!

What's csvLib? If it's the CSV UDF from my site (or mine from KORG) just call it "CSV.UDF" - using "lib" as part of a udf filename implies it's a Library of related functions - CSV is a single UDF, so name it as such. This isn't contributing to your error, but deviates from standards, and that could come back to bite you (you know where) later.

At this stage, drop the SetConsole and MessageBox garbage - too complicated. Open a command prompt & CD to your folder where these scripts are and run "Kix32 myscript.kix" (using your script name, of course).

Good way to debug: Get the MSG() UDF and include that, too.. declare a global var called $DEBUG, set it to 1, and then sprinkle your code with
Dbg('Line 29: X=' + $X)
type messages - they'll display on the command line. The "Line 29" is an example - you're better served by logical names or messages, like
Dbg('result of CSV(Readline) is ' + $Temp)
When you're done debugging, simply set $DEBUG=0.

This will also allow you to enumerate the array values without popping up dozens of message boxes. Consider the code below:


Break On
 
; Glenn's style - global vars (including macros) are ALL_CAPS, local vars are Mixed_Case 
; helps to consistently identify a variable's scope 
; also - dim each var or related var set with comments to identify their purpose 
 
Global $DEBUG			; debug flag 
 
Dim $Row, $Col			; row and column references 
Dim $I				; index pointer 
 
 
$DEBUG = 1			; enable debugging 
 
$Row = 4			; start placing data at A4 
$Col = 'A'
 
 
call @ScriptDir + "\xlLib.udf"
call @ScriptDir + "\csv.UDF"
call @ScriptDir + "\msg.UDF"
 
 
$oXL = xlInit()
$outPutFile = "C:\KIX\test.xls"
 
 
$wBO = xlNewBook($oXL)
 
xlSheetAdd($oXL, 1, 'Sheet1')
 
xlSheetSelect($oXL, "Sheet1")
 
If Open(2,'C:\KIX\732AMS.csv') = 0
  $aryData = CSV(ReadLine(2))
  While Not @ERROR
    ; process the array data. Since it's an array, you could prolly just 
    ; use xlRangeValue to write the data, Assumes you've already created 
    ; the Excel connection object, workbook, and sheet 
 
; display the array data for debugging 
Dbg('' + (UBound($aryData) + 1) + ' fields were returned by CSV()')
For $I = 0 to UBound($aryData)
  Dbg('' + $I + ': ' $aryData[$I])
Next
 
 
 
; This will NOT work unless you define and manage the Row and Col values!! 
; You need to initialize them, and then you need to increment either the row  
; or column pointer after each - see DIM and definitions above, increment below 
    $ = xlRangeValue($oXL, '' + $Row + $Col, $aryData, 'Sheet1')
    $Row = $Row + 1		; increment row pointer 
 
    $aryData = CSV(ReadLine(2))	; read next row from input file, if any 
 
  Loop
  $ = Close(2)
Else
  MessageBox(@SERROR, "ERROR", 64)
EndIf
 
xlFile($oXL, 2, 'C:\KIX\test.xls')
 

Glenn

Edited by Glenn Barnas (2008-07-29 11:44 PM)
Edit Reason: bad line breaks

_________________________
Actually I am a Rocket Scientist! \:D