Hi,
I want read line by line and characters. The characters are fix length
text file, no specific delimited method between each fields. The first
line is header line, the last line is footer. Between the first line
and last line is the content, and I will have to load the content to
database.
How to read line by line? I use For lineNum = LBound(lines) To
(UBound(lines) - 1) which generate error because it does read the
array.
Can someone show me how?
Thx
sample file:
------------------------------------------
H2004/07/2709:52:484.0TEST123MARKETING800302096510
D009084826009084826397000763333WITOWSKIDICK 41000620000520000010
F000W20040727FR3970007122228000000124444NWITOWSKID ICK 20040727250USD
D.........
F.........
T11 0 0 11 0 4250 0 0
my code:
-------------------------------------------------
Public Function ProcessRET(ByRef strFilepath As String)
Dim EpayConnection As New SqlConnection
Dim cmdBatchName As New SqlCommand
Dim dtrBatchName As SqlDataReader
EpayConnection.ConnectionString = strEpayDBConn
With cmdBatchName
.Connection = EpayConnection
.CommandText = "SELECT File_Name FROM EPay_Batch_Table Where
File_Status=2"
End With
EpayConnection.Open()
dtrBatchName = cmdBatchName.ExecuteReader()
dtrBatchName.Read()
Dim strRetFileName As String
strRetFileName = dtrBatchName("File_Name")
Dim ReturnFileName As String = strRetFileName.Replace(".in", ".RET")
Dim flRetBatch As File
Dim stRetBatch As FileStream
Dim smRetBatch As StreamReader
Try
Dim sr As New StreamReader(strFilepath &
ReturnFileName)
'Open the text file into a stream reader
Dim sRetLine As String
Dim sBatchNum As String
Dim sRecordType As String
Dim sEmpID As String
Dim sSSN As String
Dim sCardNum As Int32
Dim sErrorCode As String
Try
Dim lines() As String
Dim contents As String
Dim lineNum As Integer
sRetLine = sr.ReadLine
lines = Split(contents, vbCrLf)
If Left$(sRetLine, 1) = "H" Then
sBatchNum = (Mid$(sRetLine, 73, 13))
Dim BatchNum As Int32
BatchNum = Convert.ToInt32(sBatchNum)
End If
sRetLine = sr.ReadLine
For lineNum = LBound(lines) To (UBound(lines) - 1)
'sRetLine = sr.ReadLine
If Left$(sRetLine, 1) = "D" Or "R" Then
sBatchNum = RTrim(Mid$(sRetLine, 73, 85))
End If
Next lineNum
Catch err As Exception
MsgBox("File retrieve fail", err.Message)
End
End Try
Catch
End Try
End Function
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*