dbTalk Databases Forums  

Active X script to read text file, tab-delimited

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Active X script to read text file, tab-delimited in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
CD
 
Posts: n/a

Default Active X script to read text file, tab-delimited - 10-25-2005 , 12:55 PM






I am trying to write a script to read a tab delimited text file. I am not
clear on how to map the tabbed data to a column. I am not a programmer but
I am ttying and need some guidance. I found the following and got it work
as far as reading the tabbed file, but how to do the tab data to a column
for insert? I have done this fixed width files before but the tab-delimited
is getting me. I started down the road of building the Values for
insert..not sure if this is correct way or not. I end up with a extra
comma, too.

'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Function Main()
Const ForReading = 1, ForWriting = 2, ForAppend = 8
dim fso, tsFile, varLine, strDelimiter, strLine, ValueMsg, strTextFilePath
strTextFilePath = "d:\mfe20051002.log"

set fso = createobject("Scripting.FileSystemObject")
set tsFile = fso.OpenTextFile(strTextFilePath, 1)
strDelimiter = vbTab '(for tab delimited)
'strDelimiter = "," '(for comma delimited)
strLine = tsFile.ReadLine
strLine = tsFile.ReadLine
do while not tsFile.AtEndOfStream
strLine = tsFile.ReadLine
varLine = split(strLine, strDelimiter)
ValueMsg = "Values("
for ii = 0 to ubound(varLine)
ValueMsg = ValueMsg & varLine(ii) & ", "
next
' msgbox ValueMsg
loop

Main = DTSTaskExecResult_Success
End Function



Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: Active X script to read text file, tab-delimited - 10-25-2005 , 01:01 PM






Why not just use DTS proper to do the import rather than coding thsi all
yourself?

Can the Text File connection not handle the format?


--
Darren Green
http://www.sqldts.com
http://www.sqlis.com

"CD" <mcdye1 (AT) hotmail (DOT) REMOVETHIS.com> wrote

Quote:
I am trying to write a script to read a tab delimited text file. I am not
clear on how to map the tabbed data to a column. I am not a programmer but
I am ttying and need some guidance. I found the following and got it work
as far as reading the tabbed file, but how to do the tab data to a column
for insert? I have done this fixed width files before but the
tab-delimited is getting me. I started down the road of building the
Values for insert..not sure if this is correct way or not. I end up with a
extra comma, too.

'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Function Main()
Const ForReading = 1, ForWriting = 2, ForAppend = 8
dim fso, tsFile, varLine, strDelimiter, strLine, ValueMsg, strTextFilePath
strTextFilePath = "d:\mfe20051002.log"

set fso = createobject("Scripting.FileSystemObject")
set tsFile = fso.OpenTextFile(strTextFilePath, 1)
strDelimiter = vbTab '(for tab delimited)
'strDelimiter = "," '(for comma delimited)
strLine = tsFile.ReadLine
strLine = tsFile.ReadLine
do while not tsFile.AtEndOfStream
strLine = tsFile.ReadLine
varLine = split(strLine, strDelimiter)
ValueMsg = "Values("
for ii = 0 to ubound(varLine)
ValueMsg = ValueMsg & varLine(ii) & ", "
next
' msgbox ValueMsg
loop

Main = DTSTaskExecResult_Success
End Function




Reply With Quote
  #3  
Old   
CD
 
Posts: n/a

Default Re: Active X script to read text file, tab-delimited - 10-25-2005 , 01:28 PM



Thank for the reply,

I am going down this road due to the fact that the file is in use. Using
the Text Connection in DTS it is not able to open the file. But using
notepad I can open the file. My thought is the TextConn is trying to open
the file in a locked mode, maybe? Hence trying to open this way.

I tired the code below and was able to open the active file as expected.

"Darren Green" <darren.green (AT) reply-to-newsgroup-sqldts (DOT) com> wrote

Quote:
Why not just use DTS proper to do the import rather than coding thsi all
yourself?

Can the Text File connection not handle the format?


--
Darren Green
http://www.sqldts.com
http://www.sqlis.com

"CD" <mcdye1 (AT) hotmail (DOT) REMOVETHIS.com> wrote in message
news:%23s%23nD1Y2FHA.1188 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
I am trying to write a script to read a tab delimited text file. I am not
clear on how to map the tabbed data to a column. I am not a programmer
but I am ttying and need some guidance. I found the following and got it
work as far as reading the tabbed file, but how to do the tab data to a
column for insert? I have done this fixed width files before but the
tab-delimited is getting me. I started down the road of building the
Values for insert..not sure if this is correct way or not. I end up with
a extra comma, too.

'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Function Main()
Const ForReading = 1, ForWriting = 2, ForAppend = 8
dim fso, tsFile, varLine, strDelimiter, strLine, ValueMsg,
strTextFilePath
strTextFilePath = "d:\mfe20051002.log"

set fso = createobject("Scripting.FileSystemObject")
set tsFile = fso.OpenTextFile(strTextFilePath, 1)
strDelimiter = vbTab '(for tab delimited)
'strDelimiter = "," '(for comma delimited)
strLine = tsFile.ReadLine
strLine = tsFile.ReadLine
do while not tsFile.AtEndOfStream
strLine = tsFile.ReadLine
varLine = split(strLine, strDelimiter)
ValueMsg = "Values("
for ii = 0 to ubound(varLine)
ValueMsg = ValueMsg & varLine(ii) & ", "
next
' msgbox ValueMsg
loop

Main = DTSTaskExecResult_Success
End Function






Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.