VB6 ActiveX Distribute Without DDFs Code Generator -
10-17-2004
, 09:49 AM
Here is a function that will generate the VB6 code to enable you to
distribute applications without the DDFs. You must start with one set
of DDFs of course. Remember to reference the OCX in your project, no
need to drop the component on a form.
Assuming that you installed the sample databases in the "C" directory
you would call the function like this...
Debug.Print GetTableInfo("C:\PVSW\Demodata", "Department",
"Department.mkd")
This will fill the immediate window with code that you can paste
directly into your project.
enjoy,
-Henry
Private Function GetTableInfo(myDDFPath As String, myTableName As
String, myLocation As String) As String
Dim Indexes As Variant
Dim fields As Variant
Dim temp As Variant
Dim RetVal As String
Dim flds As String
Dim idxs As String
Set VA = New VAccessLib.VAccess
RetVal = "Dim My" & myTableName & " As New VAccessLib.VAccess" &
vbCrLf
With VA
.RefreshLocations = True
.DdfPath = myDDFPath
.TableName = myTableName
.Location = myLocation
fields = .FieldList
If Not IsEmpty(fields) Then
For i = 0 To UBound(fields, 2)
For j = 0 To UBound(fields, 1)
temp = (fields(j, i))
If IsNumeric(temp) Then
flds = flds & "MyFields(" & CStr(j) & "," &
CStr(i) & ") = " & CStr(fields(j, i)) & vbCrLf
Else
flds = flds & "MyFields(" & CStr(j) & "," &
CStr(i) & ") = " & Chr(34) & Trim(CStr(fields(j, i))) & Chr(34) &
vbCrLf
End If
Next j
Next i
End If
RetVal = RetVal & vbCrLf &
"'****************************************" & vbCrLf
RetVal = RetVal & "'FIELDS" & vbCrLf
RetVal = RetVal & "'****************************************" &
vbCrLf
RetVal = RetVal & "Dim MyFields(0 To " & (j - 1) & ", 0 To " & (i
- 1) & ") as Variant" & vbCrLf & flds
Indexes = .IndexList
If Not IsEmpty(Indexes) Then
For i = 0 To UBound(Indexes, 2)
For j = 0 To UBound(Indexes, 1)
temp = (Indexes(j, i))
If IsNumeric(temp) Then
idxs = idxs & "MyIndexes(" & CStr(j) & "," &
CStr(i) & ") = " & CStr(Indexes(j, i)) & vbCrLf
Else
idxs = idxs & "MyIndexes(" & CStr(j) & "," &
CStr(i) & ") = " & Chr(34) & Trim(CStr(Indexes(j, i))) & Chr(34) &
vbCrLf
End If
Next j
Next i
End If
RetVal = RetVal & vbCrLf &
"'****************************************" & vbCrLf
RetVal = RetVal & "'INDEXES" & vbCrLf
RetVal = RetVal & "'****************************************" &
vbCrLf
RetVal = RetVal & "Dim MyIndexes(0 To " & (j - 1) & ", 0 To " & (i
- 1) & ") as Variant" & vbCrLf & idxs
RetVal = RetVal & "With My" & myTableName & vbCrLf
RetVal = RetVal & vbTab & ".RefreshLocations = False" & vbCrLf
RetVal = RetVal & vbTab & ".TableName = " & Chr(34) & myTableName
& Chr(34) & vbCrLf
RetVal = RetVal & vbTab & ".Location = " & Chr(34) & myLocation &
Chr(34) & vbCrLf
RetVal = RetVal & vbTab & ".FieldList = MyFields" & vbCrLf
RetVal = RetVal & vbTab & ".IndexList = MyIndexes" & vbCrLf
RetVal = RetVal & vbTab & ".Open" & vbCrLf
RetVal = RetVal & vbTab & ".GetFirst" & vbCrLf
RetVal = RetVal & vbTab & ".Close" & vbCrLf
RetVal = RetVal & "End With" & vbCrLf
End With
GetTableInfo = RetVal
End Function |