I'd implemented what i need for the project but i found that the code is lengthly and not well practice...
Some more i found that the code keep repeating in some kind of format.....
However, at the moment i still thinking on the way to simplify it...Thanks if anyone can help.....

Do While Not rs.EOF()
            see = rs.Fields("" & process & "").Value
            Glide = rs.Fields("Glide").Value
            strmac = Mid(see, 1, 2)
            str = Mid(see, 6, 16)
            storedate = Split(str, " ")
            vDateTime = Convert.ToDateTime(storedate(1))
            DropDownList3.Text = storedate(0)

            Select Case (strmac)
                Case "" & Mid(mac(0), 5, 2) & ""
                    If (vDateTime.Hour = "01") Then
                        'Count1 = Count1 + 1
                        machinecount(1, 0) = machinecount(1, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(1, 0) = GHTcount(1, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "02") Then
                        'Count2 = Count2 + 1
                        machinecount(2, 0) = machinecount(2, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(2, 0) = GHTcount(2, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "03") Then
                        'Count3 = Count3 + 1
                        machinecount(3, 0) = machinecount(3, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(3, 0) = GHTcount(3, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "04") Then
                        'Count4 = Count4 + 1
                        machinecount(4, 0) = machinecount(4, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(4, 0) = GHTcount(4, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "05") Then
                        'Count5 = Count5 + 1
                        machinecount(5, 0) = machinecount(5, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(5, 0) = GHTcount(5, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "06") Then
                        'Count6 = Count6 + 1
                        machinecount(6, 0) = machinecount(6, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(6, 0) = GHTcount(6, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "07") Then
                        'Count7 = Count7 + 1
                        machinecount(7, 0) = machinecount(7, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(7, 0) = GHTcount(7, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "08") Then
                        'Count8 = Count8 + 1
                        machinecount(8, 0) = machinecount(8, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(8, 0) = GHTcount(8, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "09") Then
                        'Count9 = Count9 + 1
                        machinecount(9, 0) = machinecount(9, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(9, 0) = GHTcount(9, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "10") Then
                        'Count10 = Count10 + 1
                        machinecount(10, 0) = machinecount(10, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(10, 0) = GHTcount(10, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "11") Then
                        'Count11 = Count11 + 1
                        machinecount(11, 0) = machinecount(11, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(11, 0) = GHTcount(11, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "12") Then
                        'Count12 = Count12 + 1
                        machinecount(12, 0) = machinecount(12, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(12, 0) = GHTcount(12, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "13") Then
                        'Count13 = Count13 + 1
                        machinecount(13, 0) = machinecount(13, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(13, 0) = GHTcount(13, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "14") Then
                        'Count14 = Count14 + 1
                        machinecount(14, 0) = machinecount(14, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(14, 0) = GHTcount(14, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "15") Then
                        'Count15 = Count15 + 1
                        machinecount(15, 0) = machinecount(15, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(15, 0) = GHTcount(15, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "16") Then
                        'Count16 = Count16 + 1
                        machinecount(16, 0) = machinecount(16, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(16, 0) = GHTcount(16, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "17") Then
                        'Count17 = Count17 + 1
                        machinecount(17, 0) = machinecount(17, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(17, 0) = GHTcount(17, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "18") Then
                        'Count18 = Count18 + 1
                        machinecount(18, 0) = machinecount(18, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(18, 0) = GHTcount(18, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "19") Then
                        'Count19 = Count19 + 1
                        machinecount(19, 0) = machinecount(19, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(19, 0) = GHTcount(19, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "20") Then
                        'Count20 = Count20 + 1
                        machinecount(20, 0) = machinecount(20, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(20, 0) = GHTcount(20, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "21") Then
                        'Count21 = Count21 + 1
                        machinecount(21, 0) = machinecount(21, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(21, 0) = GHTcount(21, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "22") Then
                        'Count22 = Count22 + 1
                        machinecount(22, 0) = machinecount(22, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(22, 0) = GHTcount(22, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "23") Then
                        'Count23 = Count23 + 1
                        machinecount(23, 0) = machinecount(23, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(23, 0) = GHTcount(23, 0) + 1
                        End If
                        rs.MoveNext()
                    ElseIf (vDateTime.Hour = "00") Then
                        'Count24 = Count24 + 1
                        machinecount(24, 0) = machinecount(24, 0) + 1
                        If rs.Fields("Glide").Value = " 1 GPASS" Then
                            GHTcount(24, 0) = GHTcount(24, 0) + 1
                        End If
                        rs.MoveNext()
                    End If
.....
.....
End Select

Notes:
1.The BIG While loop is to read through what is contained in the database line by line...
2.The mac(i) is a dynamic array of unknown size, at this moment i reserve 10 elements for it.
3.machinecount(X,Y) ranging from X=1 to 24 for 1 day and Y ranging from 0 to maximum of 10 denoting 10 machines for one day record.

Recommended Answers

All 2 Replies

Get rid of the if and all those elseif and replace with this:

Dim count1 As Integer = CInt(vDateTime.Hour)
                machinecount(count1, 0) += 1
                If rs.Fields("Glide").Value = " 1 GPASS" Then
                    GHTcount(count1, 0) += 1
                End If
                rs.MoveNext()

Get rid of the if and all those elseif and replace with this:

Dim count1 As Integer = CInt(vDateTime.Hour)
                machinecount(count1, 0) += 1
                If rs.Fields("Glide").Value = " 1 GPASS" Then
                    GHTcount(count1, 0) += 1
                End If
                rs.MoveNext()

well...thts not a big prob..but thanks...
now i have 10 conditions to met..hence it is very lengthly in code......
the one i show above just for 1 condition only...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.