Skip to main content
Removed performance tag, I do not want to optimize this program performance wise (having an access table shows this), but rather by number of lines and readability. (It is also fast enough for its use)
Link
Sifu
  • 263
  • 1
  • 10
edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Fixed small mistake
Source Link
Sifu
  • 263
  • 1
  • 10
Using thisConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""Striped source""")
    Using thisCommand As OleDbCommand = thisConnection.CreateCommand

        thisConnection.Open()

        'This query is to get the information
        thisCommand.CommandText = "SELECT [Minimum Length] " & _
                                    "FROM Stats " & _
                                    "WHERE  ([N° Cylinder] = @cylinder) AND ([N° Section] = 0)"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder

        Dim thisReader As OleDbDataReader = thisCommand.ExecuteReader()
        If (thisReader.Read()) Then
            cylinderLengthMin = thisReader.GetValue(0)
        End If
        thisReader.Close()

        'This query is to get the number of stages of the cylinder
        thisCommand.CommandText = "SELECT Stroke " & _
                                    "FROM (Stats) " & _
                                    "WHERE ([N° Cylinder] = @cylinder) " & _
                                    "ORDER BY [N° Section]"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder)

        thisReader = thisCommand.ExecuteReader()
        count = -1
        Dim condition As Boolean = True
        Dim temp As String
        'This loop gets the strokes of the stages
        While (thisReader.Read()) And condition
            temp = thisReader.GetValue(0).ToString()
            If thisReader.GetValue(0).ToString() = "" Then
                condition = False
            Else
                count += 1
            End If
        End While
        countMax = count 'This is used later for array formatting
        thisReader.Close()

        If countMax = -1 Then
            Throw New SQLException("There has been an error with the database query.")
        End If

        'This query is to gather the data. It is stored in Imperial in the DataBase.
        ReDim cylinderOutsideDiameter(countMax)
        ReDim cylinderInsideDiameter(countMax)
        ReDim cylinderSectionStroke(countMax)
        ReDim cylinderSectionRetracted(countMax)
        ReDim cylinderIDStopRing(countMax)

        thisCommand.CommandText = "SELECT Stroke, [Retracted Length], [Inside Diameter], [Outside Diameter],  [Non-contact Diameter]" & _
                                    "FROM (Stats) " & _
                                    "WHERE ([N° Cylinder] = @cylinder) " & _
                                    "ORDER BY [N° Section]"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder)

        thisReader = thisCommand.ExecuteReader()

        count = 0
        While (thisReader.Read()) AndAlso count <= countMax 'Scans each row and adds it to respective string/double array
            For i = 0 To 34
                If thisReader.GetValue(i).ToString() = "" Then
                    Throw New SQLException("There has been an error with the database query.")
                End If
            Next
            cylinderSectionStroke(count) = thisReader.GetValue(0)
            cylinderSectionRetracted(count) = thisReader.GetValue(1)
            cylinderInsideDiameter(count) = thisReader.GetValue(2)
            cylinderOutsideDiameter(count) = thisReader.GetValue(3)
            cylinderIDStopRing(count) = thisReader.GetValue(4)
            count += 1
        End While

        thisReader.Close()
        thisConnection.Close()
    End Using
End Using
Using thisConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""Striped source""")
    Using thisCommand As OleDbCommand = thisConnection.CreateCommand

        thisConnection.Open()

        'This query is to get the information
        thisCommand.CommandText = "SELECT [Minimum Length] " & _
                                    "FROM Stats " & _
                                    "WHERE  ([N° Cylinder] = @cylinder) AND ([N° Section] = 0)"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder

        Dim thisReader As OleDbDataReader = thisCommand.ExecuteReader()
        If (thisReader.Read()) Then
            cylinderLengthMin = thisReader.GetValue(0)
        End If
        thisReader.Close()

        'This query is to get the number of stages of the cylinder
        thisCommand.CommandText = "SELECT Stroke " & _
                                    "FROM (Stats) " & _
                                    "WHERE ([N° Cylinder] = @cylinder) " & _
                                    "ORDER BY [N° Section]"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder)

        thisReader = thisCommand.ExecuteReader()
        count = -1
        Dim condition As Boolean = True
        Dim temp As String
        'This loop gets the strokes of the stages
        While (thisReader.Read()) And condition
            temp = thisReader.GetValue(0).ToString()
            If thisReader.GetValue(0).ToString() = "" Then
                condition = False
            Else
                count += 1
            End If
        End While
        countMax = count 'This is used later for array formatting
        thisReader.Close()

        If countMax = -1 Then
            Throw New SQLException("There has been an error with the database query.")
        End If

        'This query is to gather the data. It is stored in Imperial in the DataBase.
        ReDim cylinderOutsideDiameter(countMax)
        ReDim cylinderInsideDiameter(countMax)
        ReDim cylinderSectionStroke(countMax)
        ReDim cylinderSectionRetracted(countMax)
        ReDim cylinderIDStopRing(countMax)

        thisCommand.CommandText = "SELECT Stroke, [Retracted Length], [Inside Diameter], [Outside Diameter],  [Non-contact Diameter]" & _
                                    "FROM (Stats) " & _
                                    "WHERE ([N° Cylinder] = @cylinder) " & _
                                    "ORDER BY [N° Section]"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder)

        thisReader = thisCommand.ExecuteReader()

        count = 0
        While (thisReader.Read()) AndAlso count <= countMax 'Scans each row and adds it to respective string/double array
            For i = 0 To 3
                If thisReader.GetValue(i).ToString() = "" Then
                    Throw New SQLException("There has been an error with the database query.")
                End If
            Next
            cylinderSectionStroke(count) = thisReader.GetValue(0)
            cylinderSectionRetracted(count) = thisReader.GetValue(1)
            cylinderInsideDiameter(count) = thisReader.GetValue(2)
            cylinderOutsideDiameter(count) = thisReader.GetValue(3)
            cylinderIDStopRing(count) = thisReader.GetValue(4)
            count += 1
        End While

        thisReader.Close()
        thisConnection.Close()
    End Using
End Using
Using thisConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""Striped source""")
    Using thisCommand As OleDbCommand = thisConnection.CreateCommand

        thisConnection.Open()

        'This query is to get the information
        thisCommand.CommandText = "SELECT [Minimum Length] " & _
                                    "FROM Stats " & _
                                    "WHERE  ([N° Cylinder] = @cylinder) AND ([N° Section] = 0)"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder

        Dim thisReader As OleDbDataReader = thisCommand.ExecuteReader()
        If (thisReader.Read()) Then
            cylinderLengthMin = thisReader.GetValue(0)
        End If
        thisReader.Close()

        'This query is to get the number of stages of the cylinder
        thisCommand.CommandText = "SELECT Stroke " & _
                                    "FROM (Stats) " & _
                                    "WHERE ([N° Cylinder] = @cylinder) " & _
                                    "ORDER BY [N° Section]"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder)

        thisReader = thisCommand.ExecuteReader()
        count = -1
        Dim condition As Boolean = True
        Dim temp As String
        'This loop gets the strokes of the stages
        While (thisReader.Read()) And condition
            temp = thisReader.GetValue(0).ToString()
            If thisReader.GetValue(0).ToString() = "" Then
                condition = False
            Else
                count += 1
            End If
        End While
        countMax = count 'This is used later for array formatting
        thisReader.Close()

        If countMax = -1 Then
            Throw New SQLException("There has been an error with the database query.")
        End If

        'This query is to gather the data. It is stored in Imperial in the DataBase.
        ReDim cylinderOutsideDiameter(countMax)
        ReDim cylinderInsideDiameter(countMax)
        ReDim cylinderSectionStroke(countMax)
        ReDim cylinderSectionRetracted(countMax)
        ReDim cylinderIDStopRing(countMax)

        thisCommand.CommandText = "SELECT Stroke, [Retracted Length], [Inside Diameter], [Outside Diameter],  [Non-contact Diameter]" & _
                                    "FROM (Stats) " & _
                                    "WHERE ([N° Cylinder] = @cylinder) " & _
                                    "ORDER BY [N° Section]"
        thisCommand.Parameters.AddWithValue("@cylinder", cylinder)

        thisReader = thisCommand.ExecuteReader()

        count = 0
        While (thisReader.Read()) AndAlso count <= countMax 'Scans each row and adds it to respective string/double array
            For i = 0 To 4
                If thisReader.GetValue(i).ToString() = "" Then
                    Throw New SQLException("There has been an error with the database query.")
                End If
            Next
            cylinderSectionStroke(count) = thisReader.GetValue(0)
            cylinderSectionRetracted(count) = thisReader.GetValue(1)
            cylinderInsideDiameter(count) = thisReader.GetValue(2)
            cylinderOutsideDiameter(count) = thisReader.GetValue(3)
            cylinderIDStopRing(count) = thisReader.GetValue(4)
            count += 1
        End While

        thisReader.Close()
        thisConnection.Close()
    End Using
End Using
Source Link
Sifu
  • 263
  • 1
  • 10
Loading