Need xtra funtionality
- From: "Hilton" <get_chatting@xxxxxxxxxxx>
- Date: Mon, 11 Dec 2006 13:10:41 +0200
Hi below is a programme which reads records from a text file and aggregates
over certain fields:
The file is as follows (example only code below does not tie up with this
file format)
Input:
Acc,Trx,Port,Count,Prem
001,Pv,1,12,100
001,PI,1,10,100
001,PI,1,11,100
001,Cu,1,11,100
002,PI,2,9,150
002,PI,2,10,150
002,Cu,2,10,150
003,Pv,1,9,115
003,PI,1,6,115
003,PI,1,8,115
003,Cu,1,8,115
004,PI,2,1,130
004,Cu,2,1,130
===========================
Output:
Acc,Trx,Port,TotCount,TotPrem
001,Pv,1,12,100
001,PI,1,21,200
001,Cu,1,11,100
002,NB,2,9,150 *** (change PI to NB)
002,PI,2,10,150
002,Cu,2,10,150
003,Pv,1,9,115
003,PI,1,14,230
003,Cu,1,8,115
004,NB,2,1,130 *** (change PI to NB)
004,Cu,2,1,130
===========================
My Code:
Sub Button4_Click()
Dim strLine As String
Dim strAcc As String
Dim strBu As String
Dim strMovm As String
Dim NewArray(100, 7)
Dim polval1 As String
Dim polval2 As String
Dim intcounter As Integer
Dim intAcc As String
Dim lngStatus As Long
Dim lngCnt As Long
Dim lngPremium As Long
Dim blnFound As Boolean
Dim intUniqueItems As Integer: intUniqueItems = 0
Open "inBk.txt" For Input As #1
Open "outBk.txt" For Output As #2
Do Until EOF(1)
strAcc = Mid$(strLine, 6, 1)
strBu = Mid$(strLine, 3, 2)
strMovm = Mid$(strLine, 258, 16)
lngStatus = CLng(Mid$(strLine, 35, 1))
lngCnt = 1
lngPremium = CLng(Mid$(strLine, 55, 9))
strMth = Mid$(strLine, 252, 2)
txtstr = Mid$(strLine, 258, 16)
blnFound = False
' check whether this already exists, or needs a new cell in the array.
For intcounter = LBound(NewArray, 1) To UBound(NewArray, 1)
' check for matching Acc and Status
If NewArray(intcounter, 1) = strAcc And NewArray(intcounter, 2) =
txtstr And NewArray(intcounter, 3) = lngStatus And NewArray(intcounter, 6) =
strBu Then
NewArray(intcounter, 4) = CLng(NewArray(intcounter, 4)) +
lngPremium
NewArray(intcounter, 5) = CLng(NewArray(intcounter, 5)) + 1
blnFound = True
End If
Next
If Not blnFound Then
intUniqueItems = intUniqueItems + 1
intAcc = strAcc
NewArray(intUniqueItems, 1) = strAcc
NewArray(intUniqueItems, 6) = strBu
NewArray(intUniqueItems, 2) = txtstr
NewArray(intUniqueItems, 7) = strMth
NewArray(intUniqueItems, 3) = lngStatus
NewArray(intUniqueItems, 5) = lngCnt
NewArray(intUniqueItems, 4) = lngPremium
End If
Loop
Print #2, "Ind" & "," & "BU" & "," & "Trx_Name" & "," & "Status" & "," &
"Prem" & "," & "Count"
For intcounter = 1 To 8785
If NewArray(intcounter, 1) & vbNullString <> vbNullString Then
Print #2, NewArray(intcounter, 1) & "," & NewArray(intcounter, 6) &
"," & NewArray(intcounter, 2) & "," & NewArray(intcounter, 3) & "," &
NewArray(intcounter, 4) & "," & NewArray(intcounter, 5)
End If
Next intcounter
Close #1
Close #2
MsgBox ("End of run!")
End Sub
OK so what I would like to do is amend the output i.e. when acc changes and
the first movement is "PI" then the output array should make the trx = "NB"
I suspect the change happens at this line:
NewArray(intUniqueItems, 2) = txtstr
However when I tweak the code then somehow the aggregation gets stuuffed up!
Can someone pleeease fix?
Thanks
Hilton
.
- Prev by Date: Re: [MULTIPOSTED] VB6 / COM Question
- Next by Date: "ActiveX component can't create object" after update
- Previous by thread: VB6 / COM Question
- Next by thread: "ActiveX component can't create object" after update
- Index(es):
Loading