Hello,
Here is my code:
Imports System
Imports System.IO
Imports System.Diagnostics
Imports APS.Infrastructure
Imports System.Data.SqlClient
Imports cltComps
Public Class Presort
Dim dsResult As Integer
Private Function AndNotLineIndexOf(ByVal line As String, ByVal SearchFor As String)
Dim TotalPieces As Integer
Dim NumPieces As Integer
Dim Rate As Integer
If line.IndexOf(SearchFor) > 0 Then 'And Not line.IndexOf("POSTAGE STATEMENT") > 0 Then
TotalPieces = CType(line.Substring(94, 10), Integer)
Rate = line.Substring(94, 10)
NumPieces = line.Substring(94, 10)
End If
Return dsResult
End Function
Public Function ReadFile(ByVal Path As String)
Dim dsResult As Integer
Dim fs As FileStream = New FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim sr As StreamReader = New StreamReader(fs)
Dim line As String
Dim TotalPieces, NumPieces, Rate As Integer
Try
Do While sr.Peek() >= 0
line = sr.ReadLine()
TotalPieces = AndNotLineIndexOf(line, "A3 3-Digit")
AndNotLineIndexOf(line, "A2 5-Digit")
AndNotLineIndexOf(line, "A4 AADC")
Loop
Catch ex As Exception
Finally
If Not sr Is Nothing Then
sr.Close()
End If
If Not fs Is Nothing Then
fs.Close()
End If
End Try
Return dsResult
End Function
Here is where I am stuck and need help
I am trying to parse data from a text file.
I am wanting the values from line 106
.
In the file the field/ row called A1
which is column 3-4
I want the value to pull for this field for this which is column 6-12 and it will be inserted into my database table field called A1Desc
Next, for the same line field/ row called A1 I wann the value to pull for columns 46-50 and it will be inserted into my database table field called A1Rate
Here is my stored procedure to give an idea of where I am going with this:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[UpdatePostageAnalys
is]
(
@ProcessID char(5),
@A1Desc char(20),
@A1Rate decimal(19,4),
@A1Pieces int,
@A1Total decimal(19,4),
@A2Desc char(20),
@A2Rate decimal(19,4),
@A2Pieces int,
@A2Total decimal(19,4),
@A3Desc char(20),
@A3Rate decimal(19,4),
@A3Pieces int,
@A3Total decimal(19,4),
@A4Desc char(20),
@A4Rate decimal(19,4),
@A4Pieces int,
@A4Total decimal(19,4),
@A5Desc char(20),
@A5Rate decimal(19,4),
@A5Pieces int,
@A5Total decimal(19,4),
@PartAPieces int,
@PartATotal decimal(19,4),
@PartAFullTotal decimal(19,4),
--@sC1Desc char(20),
--@dC1Rate decimal(19,4),
--@iC1Pieces int,
--@dC1Total decimal(19,4),
--@sC2Desc char(20),
--@dC2Rate decimal(19,4),
--@iC2Pieces int,
--@dC2Total decimal(19,4),
---@sC3Desc char(20),
--@dC3Rate decimal(19,4),
--@iC3Pieces int,
---@dC3Total decimal(19,4),
--@sC4Desc char(20),
--@dC4Rate decimal(19,4),
---@iC4Pieces int,
---@dC4Total decimal(19,4),
---@iPartCPieces int,
---@dPartCTotal decimal(19,4),
--@dPartCFullTotal decimal(19,4),
--@dTotalMailingAmount decimal(19,4),
---@dTotalFullMailingAmoun
t decimal(19,4),
@TotalPieces int
--@iBillingID int
)
AS
UPDATE PostageAnalysis
SET
A1Desc=@A1Desc, A1Rate=@A1Rate, A1Pieces=@A1Pieces, A1Total=@A1Total,
A2Desc=@A2Desc, A2Rate=@A2Rate, A2Pieces=@A2Pieces, A2Total=@A2Total,
A3Desc=@A3Desc, A3Rate=@A3Rate, A3Pieces=@A3Pieces, A3Total=@A3Total,
A4Desc=@A4Desc, A4Rate=@A4Rate, A4Pieces=@A4Pieces, A4Total=@A4Total,
A5Desc=@A5Desc, A5Rate=@A5Rate, A5Pieces=@A5Pieces, A5Total=@A5Total,
PartAPieces=@PartAPieces, PartATotal=@PartATotal, PartAFullTotal=@PartAFullT
otal,
TotalPieces=@TotalPieces
WHERE ProcessID = @ProcessID
RETURN
I need my VB code modified to get me started on what I am trying to do and I should be able to take it from there to parse the rest of the data.
Thanks for the help.