would like to calculate the frequency of the type of value from a recordset. i want to check if the values of a columns from a table is if correct type. For example a column in a table might be defined as of type string, but in reality the data in that columns are all integer.. so i will return a result tat indicate integer is of a more suitable type than wat is defined.
so the way i'm doing now is to loop thru the recordset and check for the type, then i will have a counter, which is an array of int, to store how many times it occur. Then if all the columns return the same type
Public Function suggestType(ByVal relation As String, ByVal column As String)
Dim sqlString As String
Dim counter(1 To 13) As Integer
'Dim booleanCounter, byteCounter, dataCounter, nullCounter, decimalCounter As String
'Dim doubleCounter, intCounter, objectCounter, longCounter, shortCounter As String
'Dim singleCounter, stringCounter As String
sqlString = ""
sqlString = "SELECT distinct " & column & " From " & relation
If rec.State = adStateOpen Then rec.Close
rec.Open sqlString, conn
If rec.State = adStateOpen Then
While Not rec.EOF
Select Case TypeName(rec.Fields(0).value)
Case "Boolean"
counter(1) = counter(1) + 1
Case "Byte"
counter(2) = counter(2) + 1
Case "Char"
counter(3) = counter(3) + 1
Case "Date"
counter(4) = counter(4) + 1
Case "DBNull"
counter(5) = counter(5) + 1
Case "Decimal"
counter(6) = counter(6) + 1
Case "Double"
counter(7) = counter(7) + 1
Case "Integer"
counter(8) = counter(8) + 1
Case "Object"
counter(9) = counter(9) + 1
Case "Long"
counter(10) = counter(10) + 1
Case "Short"
counter(11) = counter(11) + 1
Case "Single"
counter(12) = counter(12) + 1
Case "String"
counter(13) = counter(13) + 1
End Select
Wend
End If
For i = 0 To 12
If counter(i) = rec.RecordCount Or rec.RecordCount = counter(i) + counter(5) Then
suggestType = i
End If
Next
rec.Close
Set rec = Nothing
End Function
is there a better,fast n more effient way to do this?
so the way i'm doing now is to loop thru the recordset and check for the type, then i will have a counter, which is an array of int, to store how many times it occur. Then if all the columns return the same type
Public Function suggestType(ByVal relation As String, ByVal column As String)
Dim sqlString As String
Dim counter(1 To 13) As Integer
'Dim booleanCounter, byteCounter, dataCounter, nullCounter, decimalCounter As String
'Dim doubleCounter, intCounter, objectCounter, longCounter, shortCounter As String
'Dim singleCounter, stringCounter As String
sqlString = ""
sqlString = "SELECT distinct " & column & " From " & relation
If rec.State = adStateOpen Then rec.Close
rec.Open sqlString, conn
If rec.State = adStateOpen Then
While Not rec.EOF
Select Case TypeName(rec.Fields(0).value)
Case "Boolean"
counter(1) = counter(1) + 1
Case "Byte"
counter(2) = counter(2) + 1
Case "Char"
counter(3) = counter(3) + 1
Case "Date"
counter(4) = counter(4) + 1
Case "DBNull"
counter(5) = counter(5) + 1
Case "Decimal"
counter(6) = counter(6) + 1
Case "Double"
counter(7) = counter(7) + 1
Case "Integer"
counter(8) = counter(8) + 1
Case "Object"
counter(9) = counter(9) + 1
Case "Long"
counter(10) = counter(10) + 1
Case "Short"
counter(11) = counter(11) + 1
Case "Single"
counter(12) = counter(12) + 1
Case "String"
counter(13) = counter(13) + 1
End Select
Wend
End If
For i = 0 To 12
If counter(i) = rec.RecordCount Or rec.RecordCount = counter(i) + counter(5) Then
suggestType = i
End If
Next
rec.Close
Set rec = Nothing
End Function
is there a better,fast n more effient way to do this?