Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statement - End If - How to increment and sum?!

Status
Not open for further replies.

londonkiwi

Programmer
Sep 25, 2000
83
NZ
As a newbie, I'm sure this can be done better.

The problem lies in the way Private Sub FinalPro_Click() works

I have pasted the (LONG) code below. I start off with this ( having pre processed an file via Private Sub procMC_Click()(abbreviate results below):

12:00:33 18/10/00 BA 1
12:00:37 18/10/00 BA 1
12:01:02 18/10/00 AB 1
12:01:27 18/10/00 AB 1
12:01:30 18/10/00 AB 1
12:01:32 18/10/00 AB 1
12:01:36 18/10/00 BA 1
12:02:14 18/10/00 AB 1
12:02:41 18/10/00 BA 1
12:03:31 18/10/00 AB 1

and really want to end up with this (FinalProc_CLick(), again abbreviated-

00300300,0043,1,18/10/00,6,0,0,0,0,0,0,0,0,0,0,0,0,0-0,0,0
00300300,0043,2,18/10/00,6,0,0,0,0,0,0,0,0,0,0,0,0,0-0,0,0
00300300,0043,1,18/10/00,12,0,0,0,0,0,0,0,0,0,0,0,0,0-0,0,0
00300300,0043,2,18/10/00,12,1,0,0,0,0,0,0,0,0,0,0,0,0-0,0,0
00300300,0043,1,18/10/00,18,0,0,0,0,0,0,0,0,0,0,0,0,0-0,0,0
00300300,0043,2,18/10/00,18,0,0,0,0,0,0,0,0,0,0,0,0,0-0,0,0

The three values after the "-" are to be the sums of the L(Light) M (Medium) and H (Heavy) vehicles. I have tried to place a "counter" routine after the End If of each CASE statement.

Why is it not working, and how do you fix it?.

Thanks in Advance

Option Explicit
Public Function GetFileName(strFileName As String) As String

'************************************
' The following is called by a procedure. A loop is set up which
'starts at the back of the filename and moves forward until a "." is found.
'We presume that everthing after the last dot in the filename is the extension,
'hence everthing infront of the "." is the filename
'**********************************

Dim iCurrChar As Integer
iCurrChar = Len(strFileName)

Do Until (Mid$(strFileName, iCurrChar, 1) = ".")
iCurrChar = iCurrChar - 1

If (iCurrChar = 1) Then
Exit Do
End If
Loop

If (iCurrChar > 1) Then
GetFileName = Left$(strFileName, iCurrChar - 1)
Else
GetFileName = ""
End If

End Function

Private Sub procMC_Click()

Dim sLine As String
Dim FileNumRead As Integer
Dim FileNumWrite As Integer
Dim lData1, lData2, lData3, lData4 As String
Dim Msg$

Dim strFilter As String 'Common dialog filter string
Dim strFileName As String 'String of file to open
Dim FileHandleRead% ' Variable to hold file handle

strFilter = "MC500(*.eco)|*.eco|Text File(*.txt)|*.txt|All files(*.*)|*.*" 'Set the common dialog filter
cdMain.Filter = strFilter

Msg$ = "Are you sure you want to quit?"

cdMain.ShowOpen ' Open the common dialog
If cdMain.FileName <> &quot;&quot; Then ' Make sure the retrieved filename is not a blank string
strFileName = cdMain.FileName ' if it is not blank open the file
Else
If MsgBox(Msg$, vbYesNo + vbQuestion, _
&quot;Exiting File Transfer&quot;) = vbYes Then
End If
Exit Sub
End If


'************************************

' The following is a call to the Function GetFileName. A loop is set up which
' starts at the back of the filename and moves forward until a &quot;.&quot; is found.
' We presume that everthing after the last dot in the filename is the extension,
' hence everthing infront of the &quot;.&quot; is the filename
'
' This code also works, but not if the file extension is > 3 char:
' sNewFile = Left(strFileName, Len(strFileName) - 4) & &quot;.txt&quot;
'

'*************************************

Dim sNewFile As String
sNewFile = GetFileName(strFileName) & &quot;.mct&quot; 'metrocount temporary file

FileHandleRead% = FreeFile 'Get a free file handle and assign it to the file handle variable
Open strFileName For Input As #FileHandleRead% 'Open the file
FileNumWrite = FreeFile
Open sNewFile For Output As #FileNumWrite

Do Until UCase(Left(sLine, 2)) = &quot;HH&quot; Or EOF(FileHandleRead%) ' want to find the end of file
Line Input #FileHandleRead%, sLine
Loop

Screen.MousePointer = vbHourglass ' Change mouse pointer to hourglass.

Do Until EOF(FileHandleRead%) ' code here to process line of data
Line Input #FileHandleRead%, sLine ' get first line of data
If UCase(Left(Trim(sLine), 2)) <> &quot;HH&quot; And UCase(Left(Trim(sLine), 1)) <> &quot;&quot; Then
lData1 = Trim(Mid(sLine, 1, 8))
lData2 = Format(Trim(Mid(sLine, 10, 8)), &quot;dd/mm/yy&quot;)
lData3 = Trim(Mid(sLine, 19, 2))
If lData3 = &quot;AB&quot; Then
lData3 = &quot;AB&quot;
Else
If lData3 = &quot;BA&quot; Then
lData3 = &quot;BA&quot;
End If
End If

lData4 = Trim(Mid(sLine, 45, 2))

Print #FileNumWrite, lData1 & &quot; &quot; & lData2 & &quot; &quot; & lData3 & &quot; &quot; & lData4
lData1 = 0: lData2 = 0: lData3 = 0: lData4 = 0
End If
Loop

Close #FileHandleRead%
Close #FileNumWrite
Screen.MousePointer = vbDefault ' Return mouse pointer to normal.

MsgBox &quot;Completed&quot;

End Sub

Private Sub cmdExit_Click()
Dim Msg$

Msg$ = &quot;Are you sure you want to quit?&quot;

If MsgBox(Msg$, vbYesNo + vbQuestion, _
&quot;Exiting File Transfer&quot;) = vbYes Then
End
End If
End Sub


Private Sub FinalPro_Click()

Dim ab1_Count(4), ab2_Count(4), ab3_Count(4), ab4_Count(4), ab5_Count(4), ab6_Count(4), ab7_Count(4), ab8_Count(4), ab9_Count(4), ab10_Count(4), ab11_Count(4), ab12_Count(4), ab13_Count(4) As Long
Dim ba1_Count(4), ba2_Count(4), ba3_Count(4), ba4_Count(4), ba5_Count(4), ba6_Count(4), ba7_Count(4), ba8_Count(4), ba9_Count(4), ba10_Count(4), ba11_Count(4), ba12_Count(4), ba13_Count(4) As Long

Dim L_TOT_06AB, L_TOT_712AB, L_TOT_1318AB, L_TOT_1924AB As Long ' light vehicles AB
Dim L_TOT_06BA, L_TOT_712BA, L_TOT_1318BA, L_TOT_1924BA As Long ' light vehicles BA

Dim M_TOT_06AB, M_TOT_712AB, M_TOT_1318AB, M_TOT_1924AB As Long ' medium vehicles AB
Dim M_TOT_06BA, M_TOT_712BA, M_TOT_1318BA, M_TOT_1924BA As Long ' medium vehicles BA

Dim H_TOT_06AB, H_TOT_712AB, H_TOT_1318AB, H_TOT_1924AB As Long ' heavy vehicles AB
Dim H_TOT_06BA, H_TOT_712BA, H_TOT_1318BA, H_TOT_1924BA As Long ' heavy vehicles BA

Dim x

Dim lLine As Long
Dim lDate1 As String

Dim FileNumRead As Integer
Dim FileNumWrite As Integer
Dim sLine As String
Dim strDate As String

Dim strFilter As String 'Common dialog filter string
Dim strFileName As String 'String of file to open
Dim FileHandleRead% ' Variable to hold file handle

Dim Msg$

strFilter = &quot;MetroCount Temp File(*.mct)|*.mct|All files(*.*)|*.*&quot; 'Set the common dialog filter
cdMain.Filter = strFilter

Msg$ = &quot;Are you sure you want to quit?&quot;
cdMain.ShowOpen ' Open the common dialog
If cdMain.FileName <> &quot;&quot; Then ' Make sure the retrieved filename is not a blank string
strFileName = cdMain.FileName ' if it is not blank open the file
Else
If MsgBox(Msg$, vbYesNo + vbQuestion, _
&quot;Exiting File Transfer&quot;) = vbYes Then
End If
Exit Sub
End If

Dim sNewFile As String

sNewFile = GetFileName(strFileName) & &quot;.txt&quot;

FileHandleRead% = FreeFile 'Get a free file handle and assign it to the file handle variable
strDate = &quot;00/00/00&quot;
L_TOT_06AB = 0
L_TOT_712AB = 0
L_TOT_1318AB = 0
L_TOT_1924AB = 0
L_TOT_06BA = 0
L_TOT_712BA = 0
L_TOT_1318BA = 0
L_TOT_1924BA = 0

M_TOT_06AB = 0
M_TOT_712AB = 0
M_TOT_1318AB = 0
M_TOT_1924AB = 0
M_TOT_06BA = 0
M_TOT_712BA = 0
M_TOT_1318BA = 0
M_TOT_1924BA = 0

H_TOT_06AB = 0
H_TOT_712AB = 0
H_TOT_1318AB = 0
H_TOT_1924AB = 0
H_TOT_06BA = 0
H_TOT_712BA = 0
H_TOT_1318BA = 0
H_TOT_1924BA = 0

Open strFileName For Input As #FileHandleRead% 'Open the file
FileNumWrite = FreeFile
Open sNewFile For Output As #FileNumWrite

Dim sNameEnd As String
sNameEnd = Trim(Right(Left(sNewFile, Len(sNewFile) - 4), 8))
Dim sNameStart As String

Do Until EOF(FileHandleRead%)
Line Input #FileHandleRead%, sLine

lDate1 = Format(Trim(Mid(sLine, 10, 8)), &quot;yyww&quot;) ' gets the year and the week
If Mid(sLine, 19, 2) = &quot;AB&quot; Then
Select Case Val(Trim(Left(sLine, 2)))
Case 0 To 6 'eg hours 0-6 in direction AB, with 13 vehicle classes
' AtoB
If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ab1_Count(1) = ab1_Count(1) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ab2_Count(1) = ab2_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ab3_Count(1) = ab3_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ab4_Count(1) = ab4_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ab5_Count(1) = ab5_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ab6_Count(1) = ab6_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ab7_Count(1) = ab7_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ab8_Count(1) = ab8_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ab9_Count(1) = ab9_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ab10_Count(1) = ab10_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ab11_Count(1) = ab11_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ab12_Count(1) = ab12_Count(1) + 1
Else: 'Class = 13 or something else !
ab13_Count(1) = ab13_Count(1) + 1
End If

L_TOT_06AB = (ab1_Count(1) + ab2_Count(1))
M_TOT_06AB = (ab3_Count(1) + ab4_Count(1) + ab5_Count(1))
H_TOT_06AB = (ab6_Count(1) + ab7_Count(1) + ab8_Count(1) + ab9_Count(1) + ab10_Count(1) + ab11_Count(1) + ab12_Count(1))

Case 7 To 12

If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ab1_Count(2) = ab1_Count(2) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ab2_Count(2) = ab2_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ab3_Count(2) = ab3_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ab4_Count(2) = ab4_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ab5_Count(2) = ab5_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ab6_Count(2) = ab6_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ab7_Count(2) = ab7_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ab8_Count(2) = ab8_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ab9_Count(2) = ab9_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ab10_Count(2) = ab10_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ab11_Count(2) = ab11_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ab12_Count(2) = ab12_Count(2) + 1
Else: 'Class = 13 or something else !
ab13_Count(2) = ab13_Count(2) + 1
End If

L_TOT_712AB = (ab1_Count(1) + ab2_Count(1))
M_TOT_712AB = (ab3_Count(1) + ab4_Count(1) + ab5_Count(1))
H_TOT_712AB = (ab6_Count(1) + ab7_Count(1) + ab8_Count(1) + ab9_Count(1) + ab10_Count(1) + ab11_Count(1) + ab12_Count(1))

Case 13 To 18

If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ab1_Count(3) = ab1_Count(3) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ab2_Count(3) = ab2_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ab3_Count(3) = ab3_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ab4_Count(3) = ab4_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ab5_Count(3) = ab5_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ab6_Count(3) = ab6_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ab7_Count(3) = ab7_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ab8_Count(3) = ab8_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ab9_Count(3) = ab9_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ab10_Count(3) = ab10_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ab11_Count(3) = ab11_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ab12_Count(3) = ab12_Count(3) + 1
Else: 'Class = 13 or something else !
ab13_Count(3) = ab13_Count(3) + 1
End If

L_TOT_1318AB = (ab1_Count(1) + ab2_Count(1))
M_TOT_1318AB = (ab3_Count(1) + ab4_Count(1) + ab5_Count(1))
H_TOT_1318AB = (ab6_Count(1) + ab7_Count(1) + ab8_Count(1) + ab9_Count(1) + ab10_Count(1) + ab11_Count(1) + ab12_Count(1))

Case 19 To 24

If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ab1_Count(4) = ab1_Count(4) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ab2_Count(4) = ab2_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ab3_Count(4) = ab3_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ab4_Count(4) = ab4_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ab5_Count(4) = ab5_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ab6_Count(4) = ab6_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ab7_Count(4) = ab7_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ab8_Count(4) = ab8_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ab9_Count(4) = ab9_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ab10_Count(4) = ab10_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ab11_Count(4) = ab11_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ab12_Count(4) = ab12_Count(4) + 1
Else: 'Class = 13 or something else !
ab13_Count(4) = ab13_Count(4) + 1
End If

L_TOT_1924AB = (ab1_Count(1) + ab2_Count(1))
M_TOT_1924AB = (ab3_Count(1) + ab4_Count(1) + ab5_Count(1))
H_TOT_1924AB = (ab6_Count(1) + ab7_Count(1) + ab8_Count(1) + ab9_Count(1) + ab10_Count(1) + ab11_Count(1) + ab12_Count(1))

End Select
Else
Select Case Val(Trim(Left(sLine, 2)))
Case 0 To 6 ' eg hours 0 to 6 AND DIRECTION B to A
If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ba1_Count(1) = ba1_Count(1) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ba2_Count(1) = ba2_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ba3_Count(1) = ba3_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ba4_Count(1) = ba4_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ba5_Count(1) = ba5_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ba6_Count(1) = ba6_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ba7_Count(1) = ba7_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ba8_Count(1) = ba8_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ba9_Count(1) = ba9_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ba10_Count(1) = ba10_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ba11_Count(1) = ba11_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ba12_Count(1) = ba12_Count(1) + 1
Else: 'Class = 13 or something else
ba13_Count(1) = ba13_Count(1) + 1
End If

L_TOT_06BA = (ab1_Count(1) + ab2_Count(1))
M_TOT_06BA = (ba3_Count(1) + ba4_Count(1) + ba5_Count(1))
H_TOT_06BA = (ba6_Count(1) + ba7_Count(1) + ba8_Count(1) + ba9_Count(1) + ba10_Count(1) + ba11_Count(1) + ba12_Count(1))

Case 7 To 12

If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ba1_Count(2) = ba1_Count(2) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ba2_Count(2) = ba2_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ba3_Count(2) = ba3_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ba4_Count(2) = ba4_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ba5_Count(2) = ba5_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ba6_Count(2) = ba6_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ba7_Count(2) = ba7_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ba8_Count(2) = ba8_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ba9_Count(2) = ba9_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ba10_Count(2) = ba10_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ba11_Count(2) = ba11_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ba12_Count(2) = ba12_Count(2) + 1
Else: 'Class = 13 or something else
ba13_Count(2) = ba13_Count(2) + 1
End If

L_TOT_712BA = (ba1_Count(1) + ba2_Count(1))
M_TOT_712BA = (ba3_Count(1) + ba4_Count(1) + ba5_Count(1))
H_TOT_712BA = (ba6_Count(1) + ba7_Count(1) + ba8_Count(1) + ba9_Count(1) + ba10_Count(1) + ba11_Count(1) + ba12_Count(1))

Case 13 To 18

If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ba1_Count(3) = ba1_Count(3) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ba2_Count(3) = ba2_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ba3_Count(3) = ba3_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ba4_Count(3) = ba4_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ba5_Count(3) = ba5_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ba6_Count(3) = ba6_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ba7_Count(3) = ba7_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ba8_Count(3) = ba8_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ba9_Count(3) = ba9_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ba10_Count(3) = ba10_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ba11_Count(3) = ba11_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ba12_Count(3) = ba12_Count(3) + 1
Else: 'Class = 13 or something else
ba13_Count(3) = ba13_Count(3) + 1
End If

L_TOT_1318BA = (ba1_Count(1) + ba2_Count(1))
M_TOT_1318BA = (ba3_Count(1) + ba4_Count(1) + ba5_Count(1))
H_TOT_1318BA = (ba6_Count(1) + ba7_Count(1) + ba8_Count(1) + ba9_Count(1) + ba10_Count(1) + ba11_Count(1) + ba12_Count(1))

Case 19 To 24

If Trim(Mid(sLine, 22, 2)) = &quot;1&quot; Then 'Class = 1
ba1_Count(4) = ba1_Count(4) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = &quot;2&quot; Then 'Class = 2
ba2_Count(4) = ba2_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;3&quot; Then 'Class = 3
ba3_Count(4) = ba3_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;4&quot; Then 'Class = 4
ba4_Count(4) = ba4_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;5&quot; Then 'Class = 5
ba5_Count(4) = ba5_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;6&quot; Then 'Class = 6
ba6_Count(4) = ba6_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;7&quot; Then 'Class = 7
ba7_Count(4) = ba7_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;8&quot; Then 'Class = 8
ba8_Count(4) = ba8_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;9&quot; Then 'Class = 9
ba9_Count(4) = ba9_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;10&quot; Then 'Class = 10
ba10_Count(4) = ba10_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;11&quot; Then 'Class = 11
ba11_Count(4) = ba11_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = &quot;12&quot; Then 'Class = 12
ba12_Count(4) = ba12_Count(4) + 1
Else: 'Class = 13 or something else
ba13_Count(4) = ba13_Count(4) + 1
End If

L_TOT_1924BA = (ba1_Count(1) + ba2_Count(1))
M_TOT_1924BA = (ba3_Count(1) + ba4_Count(1) + ba5_Count(1))
H_TOT_1924BA = (ba6_Count(1) + ba7_Count(1) + ba8_Count(1) + ba9_Count(1) + ba10_Count(1) + ba11_Count(1) + ba12_Count(1))

End Select
End If
If Mid(sLine, 10, 8) <> strDate Then
strDate = Mid(sLine, 10, 8)
'
'Direction A to B (generally North to South) = 1, B to A (generally South to North) = 2
'Format of site_no(sNameEnd),survey_no(lDate1),lane,date(strDate),time_hr,total_vol,etc
'
Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,1&quot; & &quot;,&quot; & strDate & &quot;,6,&quot; & Trim(Str(ab1_Count(1))) & &quot;,&quot; & Trim(Str(ab2_Count(1))) & &quot;,&quot; & Trim(Str(ab3_Count(1))) & &quot;,&quot; & Trim(Str(ab4_Count(1))) & &quot;,&quot; & Trim(Str(ab5_Count(1))) & &quot;,&quot; & Trim(Str(ab6_Count(1))) & &quot;,&quot; & Trim(Str(ab7_Count(1))) & &quot;,&quot; & Trim(Str(ab8_Count(1))) & &quot;,&quot; & Trim(Str(ab9_Count(1))) & &quot;,&quot; & Trim(Str(ab10_Count(1))) & &quot;,&quot; & Trim(Str(ab11_Count(1))) & &quot;,&quot; & Trim(Str(ab12_Count(1))) & &quot;,&quot; & Trim(Str(ab13_Count(1))) & &quot;-&quot; & L_TOT_06AB & &quot;,&quot; & M_TOT_06AB & &quot;,&quot; & H_TOT_06AB
Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,2&quot; & &quot;,&quot; & strDate & &quot;,6,&quot; & Trim(Str(ba1_Count(1))) & &quot;,&quot; & Trim(Str(ba2_Count(1))) & &quot;,&quot; & Trim(Str(ba3_Count(1))) & &quot;,&quot; & Trim(Str(ba4_Count(1))) & &quot;,&quot; & Trim(Str(ba5_Count(1))) & &quot;,&quot; & Trim(Str(ba6_Count(1))) & &quot;,&quot; & Trim(Str(ba7_Count(1))) & &quot;,&quot; & Trim(Str(ba8_Count(1))) & &quot;,&quot; & Trim(Str(ba9_Count(1))) & &quot;,&quot; & Trim(Str(ba10_Count(1))) & &quot;,&quot; & Trim(Str(ba11_Count(1))) & &quot;,&quot; & Trim(Str(ba12_Count(1))) & &quot;,&quot; & Trim(Str(ba13_Count(1))) & &quot;-&quot; & L_TOT_06BA & &quot;,&quot; & M_TOT_06BA & &quot;,&quot; & H_TOT_06BA

Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,1&quot; & &quot;,&quot; & strDate & &quot;,12,&quot; & Trim(Str(ab1_Count(2))) & &quot;,&quot; & Trim(Str(ab2_Count(2))) & &quot;,&quot; & Trim(Str(ab3_Count(2))) & &quot;,&quot; & Trim(Str(ab4_Count(2))) & &quot;,&quot; & Trim(Str(ab5_Count(2))) & &quot;,&quot; & Trim(Str(ab6_Count(2))) & &quot;,&quot; & Trim(Str(ab7_Count(2))) & &quot;,&quot; & Trim(Str(ab8_Count(2))) & &quot;,&quot; & Trim(Str(ab9_Count(2))) & &quot;,&quot; & Trim(Str(ab10_Count(2))) & &quot;,&quot; & Trim(Str(ab11_Count(2))) & &quot;,&quot; & Trim(Str(ab12_Count(2))) & &quot;,&quot; & Trim(Str(ab13_Count(2))) & &quot;-&quot; & L_TOT_712AB & &quot;,&quot; & M_TOT_712AB & &quot;,&quot; & H_TOT_712AB
Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,2&quot; & &quot;,&quot; & strDate & &quot;,12,&quot; & Trim(Str(ba1_Count(2))) & &quot;,&quot; & Trim(Str(ba2_Count(2))) & &quot;,&quot; & Trim(Str(ba3_Count(2))) & &quot;,&quot; & Trim(Str(ba4_Count(2))) & &quot;,&quot; & Trim(Str(ba5_Count(2))) & &quot;,&quot; & Trim(Str(ba6_Count(2))) & &quot;,&quot; & Trim(Str(ba7_Count(2))) & &quot;,&quot; & Trim(Str(ba8_Count(2))) & &quot;,&quot; & Trim(Str(ba9_Count(2))) & &quot;,&quot; & Trim(Str(ba10_Count(2))) & &quot;,&quot; & Trim(Str(ba11_Count(2))) & &quot;,&quot; & Trim(Str(ba12_Count(2))) & &quot;,&quot; & Trim(Str(ba13_Count(2))) & &quot;-&quot; & L_TOT_712BA & &quot;,&quot; & M_TOT_712BA & &quot;,&quot; & H_TOT_712BA

Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,1&quot; & &quot;,&quot; & strDate & &quot;,18,&quot; & Trim(Str(ab1_Count(3))) & &quot;,&quot; & Trim(Str(ab2_Count(3))) & &quot;,&quot; & Trim(Str(ab3_Count(3))) & &quot;,&quot; & Trim(Str(ab4_Count(3))) & &quot;,&quot; & Trim(Str(ab5_Count(3))) & &quot;,&quot; & Trim(Str(ab6_Count(3))) & &quot;,&quot; & Trim(Str(ab7_Count(3))) & &quot;,&quot; & Trim(Str(ab8_Count(3))) & &quot;,&quot; & Trim(Str(ab9_Count(3))) & &quot;,&quot; & Trim(Str(ab10_Count(3))) & &quot;,&quot; & Trim(Str(ab11_Count(3))) & &quot;,&quot; & Trim(Str(ab12_Count(3))) & &quot;,&quot; & Trim(Str(ab13_Count(3))) & &quot;-&quot; & L_TOT_1318AB & &quot;,&quot; & M_TOT_1318AB & &quot;,&quot; & H_TOT_1318AB
Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,2&quot; & &quot;,&quot; & strDate & &quot;,18,&quot; & Trim(Str(ba1_Count(3))) & &quot;,&quot; & Trim(Str(ba2_Count(3))) & &quot;,&quot; & Trim(Str(ba3_Count(3))) & &quot;,&quot; & Trim(Str(ba4_Count(3))) & &quot;,&quot; & Trim(Str(ba5_Count(3))) & &quot;,&quot; & Trim(Str(ba6_Count(3))) & &quot;,&quot; & Trim(Str(ba7_Count(3))) & &quot;,&quot; & Trim(Str(ba8_Count(3))) & &quot;,&quot; & Trim(Str(ba9_Count(3))) & &quot;,&quot; & Trim(Str(ba10_Count(3))) & &quot;,&quot; & Trim(Str(ba11_Count(3))) & &quot;,&quot; & Trim(Str(ba12_Count(3))) & &quot;,&quot; & Trim(Str(ba13_Count(3))) & &quot;-&quot; & L_TOT_1318BA & &quot;,&quot; & M_TOT_1318BA & &quot;,&quot; & H_TOT_1318BA

Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,1&quot; & &quot;,&quot; & strDate & &quot;,24,&quot; & Trim(Str(ab1_Count(4))) & &quot;,&quot; & Trim(Str(ab2_Count(4))) & &quot;,&quot; & Trim(Str(ab3_Count(4))) & &quot;,&quot; & Trim(Str(ab4_Count(4))) & &quot;,&quot; & Trim(Str(ab5_Count(4))) & &quot;,&quot; & Trim(Str(ab6_Count(4))) & &quot;,&quot; & Trim(Str(ab7_Count(4))) & &quot;,&quot; & Trim(Str(ab8_Count(4))) & &quot;,&quot; & Trim(Str(ab9_Count(4))) & &quot;,&quot; & Trim(Str(ab10_Count(4))) & &quot;,&quot; & Trim(Str(ab11_Count(4))) & &quot;,&quot; & Trim(Str(ab12_Count(4))) & &quot;,&quot; & Trim(Str(ab13_Count(4))) & &quot;-&quot; & L_TOT_1924AB & &quot;,&quot; & M_TOT_1924AB & &quot;,&quot; & H_TOT_1924AB
Print #FileNumWrite, sNameEnd & &quot;,&quot; & lDate1 & &quot;,2&quot; & &quot;,&quot; & strDate & &quot;,24,&quot; & Trim(Str(ba1_Count(4))) & &quot;,&quot; & Trim(Str(ba2_Count(4))) & &quot;,&quot; & Trim(Str(ba3_Count(4))) & &quot;,&quot; & Trim(Str(ba4_Count(4))) & &quot;,&quot; & Trim(Str(ba5_Count(4))) & &quot;,&quot; & Trim(Str(ba6_Count(4))) & &quot;,&quot; & Trim(Str(ba7_Count(4))) & &quot;,&quot; & Trim(Str(ba8_Count(4))) & &quot;,&quot; & Trim(Str(ba9_Count(4))) & &quot;,&quot; & Trim(Str(ba10_Count(4))) & &quot;,&quot; & Trim(Str(ba11_Count(4))) & &quot;,&quot; & Trim(Str(ba12_Count(4))) & &quot;,&quot; & Trim(Str(ba13_Count(4))) & &quot;-&quot; & L_TOT_1924BA & &quot;,&quot; & M_TOT_1924BA & &quot;,&quot; & H_TOT_1924BA

For x = 1 To 4
ab1_Count(x) = 0
ab2_Count(x) = 0
ab3_Count(x) = 0
ab4_Count(x) = 0
ba1_Count(x) = 0
ba2_Count(x) = 0
ba3_Count(x) = 0
ba4_Count(x) = 0
Next x
End If
Loop
Close #FileHandleRead%
Close #FileNumWrite
MsgBox &quot;Completed&quot;

End Sub
 
Start with &quot;trimming&quot; the code.
Code:
    strClass = Trim(Mid(sLine, 22, 2))
    If nor IsNumeric(strClass) then
        .....errror
    else
        lngClass = cLng(strClass) 
        ab1_Count(lngClass) = ab1_Count(ab1_Count(1) = ab1_Count(lngClass) + 1)
    End if
...........
 
Corrections.
Start with &quot;trimming&quot; the code.
Code:
    strClass = Trim(Mid(sLine, 22, 2))
    If not (IsNumeric(strClass)) then
        .....error
    else
        lngClass = cLng(strClass) 
        ab1_Count(lngClass) = ab1_Count(lngClass) + 1   
    End if
...........
 
Thanks very much for the help. Greatly Appreciated.

If you can help again.I have posted another query above!

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top