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 Count function working incorrectly

Status
Not open for further replies.

londonkiwi

Programmer
Sep 25, 2000
83
NZ

Below is part of a Select Case Routine.

I can't get the
TVOL_06BA = L_TOT_06BA + M_TOT_06BA + H_TOT_06BA "statments" etc to work properly. Where do you put them in the code sequence.

for example the txt file produced is below. The 7467 value should actually be 7+67+7

00300300,0043,1,19/10/00,12,7467,0,7,0,0,0,0,0,0,0,0,0,0,67,7,0

Thanks in advance

CODE

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)) = "1" Then 'Class = 1
ba1_Count(1) = ba1_Count(1) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = "2" Then 'Class = 2
ba2_Count(1) = ba2_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "3" Then 'Class = 3
ba3_Count(1) = ba3_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "4" Then 'Class = 4
ba4_Count(1) = ba4_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "5" Then 'Class = 5
ba5_Count(1) = ba5_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "6" Then 'Class = 6
ba6_Count(1) = ba6_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "7" Then 'Class = 7
ba7_Count(1) = ba7_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "8" Then 'Class = 8
ba8_Count(1) = ba8_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "9" Then 'Class = 9
ba9_Count(1) = ba9_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "10" Then 'Class = 10
ba10_Count(1) = ba10_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "11" Then 'Class = 11
ba11_Count(1) = ba11_Count(1) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "12" 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


Case 7 To 12

If Trim(Mid(sLine, 22, 2)) = "1" Then 'Class = 1
ba1_Count(2) = ba1_Count(2) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = "2" Then 'Class = 2
ba2_Count(2) = ba2_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "3" Then 'Class = 3
ba3_Count(2) = ba3_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "4" Then 'Class = 4
ba4_Count(2) = ba4_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "5" Then 'Class = 5
ba5_Count(2) = ba5_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "6" Then 'Class = 6
ba6_Count(2) = ba6_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "7" Then 'Class = 7
ba7_Count(2) = ba7_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "8" Then 'Class = 8
ba8_Count(2) = ba8_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "9" Then 'Class = 9
ba9_Count(2) = ba9_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "10" Then 'Class = 10
ba10_Count(2) = ba10_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "11" Then 'Class = 11
ba11_Count(2) = ba11_Count(2) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "12" 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

Case 13 To 18

If Trim(Mid(sLine, 22, 2)) = "1" Then 'Class = 1
ba1_Count(3) = ba1_Count(3) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = "2" Then 'Class = 2
ba2_Count(3) = ba2_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "3" Then 'Class = 3
ba3_Count(3) = ba3_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "4" Then 'Class = 4
ba4_Count(3) = ba4_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "5" Then 'Class = 5
ba5_Count(3) = ba5_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "6" Then 'Class = 6
ba6_Count(3) = ba6_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "7" Then 'Class = 7
ba7_Count(3) = ba7_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "8" Then 'Class = 8
ba8_Count(3) = ba8_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "9" Then 'Class = 9
ba9_Count(3) = ba9_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "10" Then 'Class = 10
ba10_Count(3) = ba10_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "11" Then 'Class = 11
ba11_Count(3) = ba11_Count(3) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "12" 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

Case 19 To 24

If Trim(Mid(sLine, 22, 2)) = "1" Then 'Class = 1
ba1_Count(4) = ba1_Count(4) + 1
ElseIf CStr(Trim(Mid(sLine, 22, 2))) = "2" Then 'Class = 2
ba2_Count(4) = ba2_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "3" Then 'Class = 3
ba3_Count(4) = ba3_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "4" Then 'Class = 4
ba4_Count(4) = ba4_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "5" Then 'Class = 5
ba5_Count(4) = ba5_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "6" Then 'Class = 6
ba6_Count(4) = ba6_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "7" Then 'Class = 7
ba7_Count(4) = ba7_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "8" Then 'Class = 8
ba8_Count(4) = ba8_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "9" Then 'Class = 9
ba9_Count(4) = ba9_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "10" Then 'Class = 10
ba10_Count(4) = ba10_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "11" Then 'Class = 11
ba11_Count(4) = ba11_Count(4) + 1
ElseIf Trim(Mid(sLine, 22, 2)) = "12" 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


End Select

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) + ba13_Count(1))


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


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


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


TVOL_06BA = L_TOT_06BA + M_TOT_06BA + H_TOT_06BA
TVOL_712BA = L_TOT_712BA + M_TOT_712BA + H_TOT_712BA
TVOL_1318BA = L_TOT_1318BA + M_TOT_1318BA + H_TOT_1318BA
TVOL_1924BA = L_TOT_1924BA + M_TOT_1924BA + H_TOT_1924BA

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; & TVOL_06AB & 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; & TVOL_06BA & 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; & TVOL_712AB & 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; & TVOL_712BA & 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; & TVOL_1318AB & 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; & TVOL_1318BA & 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; & TVOL_1924AB & 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; & TVOL_1924BA & 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;Final Process Completed&quot;

End Sub
 
You've posted a lot of code. How about giving us the problem(what you need to do). Plain English would work fine.
I can already see many &quot;problems&quot; with what you're doing, but knowing what your goal here is would be of great help, as I don't want to wade thru your code and try to figure out what you're trying to do, especially since it doesn't work. Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top