WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MrAexes on January 14, 2015, 04:12:14 AM

Title: Open delimited text file and setting column type
Post by: MrAexes on January 14, 2015, 04:12:14 AM
I'm trying to open a comma delimited text file using OpenText function and setting all the column to "Text" type to preserve the column formating.

The following code work correctly IF I'm not using that FieldInfo=vFormat :

  DB             = ObjectCreate("Excel.Application")
  DB.Visible     = @FALSE
  DB.UserControl = @FALSE
  DB.AskToUpdateLinks = @False
  DB.DisplayAlerts =@FALSE
  oAPP           = DB.Workbooks

  vFormat = ArrDimension(16)
  ArrInitialize(vFormat, 2)
  oConst = ObjectConstantsGet( DB )
  xlDelimited = oConst.xlDelimited   
  xlDoubleQuote =  oConst.xlDoubleQuote

  oAPP.OpenText(::Filename = vTranslation, Origin=437, StartRow=1, DataType=xlDelimited, TextQualifier=xlDoubleQuote, ConsecutiveDelimiter=@FALSE, Comma=@TRUE,FieldInfo=vFormat)



From Excel example I should have something similar like this:
FieldInfo:=Array(Array(1, 2), Array(2, 2))

I'm already out of idea on how to do that in wbt.

TIA!
Aexes

Title: Re: Open delimited text file and setting column type
Post by: td on January 14, 2015, 08:14:21 AM
The VBA statement 'Array(Array(1, 2), Array(2, 2))' is used to create an array of arrays.  WinBatch arrays do not support embedded arrays but safearrays do. So

Code (winbatch) Select

; Make an array of arrays.
Array = ArrDimension(5)
Temp  = ArrDimension(2)
Type  = 1
for i = 0 to 4   ; For 5 fields
   Col = i + 1
   Temp[0] = ObjectType("I1", Col)
   Temp[1] =  ObjectType("I1", Type)
   Array[i] = ObjectType("Array", Temp)
next
Title: Re: Open delimited text file and setting column type
Post by: td on January 15, 2015, 06:44:52 AM
Notice an error in my previous post.  The line 'Type  = 1' should be 'Type  = 2' to create columns of type 'text'.
Title: Re: Open delimited text file and setting column type
Post by: MrAexes on January 19, 2015, 09:52:38 PM
Thanks td for the information. Just got the chance to have a try on this and it works perfectly! One minor modification need though. I would need to rename the source file extention from '.csv' to '.txt' in order for it to work correctly.

Again thank you so much for you quide.