-
Mar 25th, 2023, 03:23 PM
#1
VB6 ADO-Rs-like "multi-column-container"
As the title already suggests, here the base-code for an implementation - which (other than a free-standing ADO-Rs), comes with support for "direct memory-access to already contained data"...
to allow for fast(er) enumerations on larger sets.
Note, that the Demo is currently dependent on RC6 -
but the only thing used from it, is the cArrayList (which wraps SafeArrays for VBs intrinsic DataTypes).
So, if you want to make the following few code-lines independent from it,
you could implement something similar (or work with "normal VB-arrays" directly in the cFld-Class)
Here's what the Form-TestCode currently looks like:
Code:
Option Explicit
Private Declare Function TextOutW Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
Private Rs As New cRec
Private Sub Form_Load()
Rs.Fields.Append "ID", vbLong
Rs.Fields.Append "Name", vbString
Rs.AddNew: Rs("ID") = 0: Rs("Name") = "Mr. X"
Rs.AddNew: Rs("ID") = 1: Rs("Name") = "Peter"
Rs.AddNew: Rs("ID") = 2: Rs("Name") = "Paul"
Rs.AddNew: Rs("ID") = 3: Rs("Name") = "Mary"
Rs.MoveFirst: Rs.Delete 'this should delete the first record ("Mr. X")
Caption = "Rec-Count: " & Rs.RecordCount 'this should report 3 in the Caption
Caption = Caption & " ...Click Me for Pointer-Listing"
Rs.MoveFirst 'the usual enumeration-loop
Do Until Rs.EOF
Debug.Print Rs!ID, Rs!Name
Rs.MoveNext
Loop
End Sub
Private Sub Form_Click() 'enumeration, directly from memory (without copying data)
FontName = "Arial": FontSize = 10: Cls
Dim L() As Long, S() As String, i As Long
If Not Rs("ID").BindToArray(L) Then MsgBox "Binding not possible": Exit Sub
If Not Rs("Name").BindToArray(S) Then MsgBox "Arr-Binding not possible": Exit Sub
For i = 0 To Rs.RecordCount - 1
TextOutW hDC, 5, i * 15, StrPtr(CStr(L(i))), Len(CStr(L(i)))
TextOutW hDC, 30, i * 15, StrPtr(S(i)), Len(S(i))
Next
Rs("ID").ReleaseArrayBinding L
Rs("Name").ReleaseArrayBinding S
End Sub
And here's the Demo-Zip:
DataTable.zip
Have fun!
Olaf
-
Mar 26th, 2023, 05:07 AM
#2
Lively Member
Re: VB6 ADO-Rs-like "multi-column-container"
Rs("ID").BindToArray(L)
Rs("Name").BindToArray(S)
Rs("ID").ReleaseArrayBinding L
Rs("Name").ReleaseArrayBinding S
Hello! Olaf, thank you very much. The code marked in red above runs with an error: Method or data member not found.
[附加]187255[/附加] [附加]187256[/附加]
Last edited by smileyoufu; Mar 26th, 2023 at 05:13 AM.
-
Mar 26th, 2023, 06:37 AM
#3
Re: VB6 ADO-Rs-like "multi-column-container"
Originally Posted by smileyoufu
Rs("ID").BindToArray(L)
Rs("Name").BindToArray(S)
Rs("ID").ReleaseArrayBinding L
Rs("Name").ReleaseArrayBinding S
The above is only available behind an instance of type: Rs As cRec
What you are using is in all likelihood: Rs As AdoDB.Recordset
(since I see different Form_Load-code in your ScreenShots)
Olaf
-
Mar 26th, 2023, 07:19 PM
#4
Re: VB6 ADO-Rs-like "multi-column-container"
cRec is great and very creative. It would be nice to be able to add sorting to cRec.
Although cArrayList includes a Sort method, sorting in cRec involves multi-column associative sorting, that is, when one field is sorted, other fields should also adjust their order according to the sorted field, which seems to be a troublesome problem.
Edit:
It is recommended to enhance the cArrayList.Sort method, such as:
Code:
Sub SortEx(Flags As CmpFlags, lcid As LCIDs, Comparer As IComparer, _
ParamArray ExternalCorrelativeArrays() As Variant)
Usage:
Code:
AL.SortEx , , , Arr1, Arr2, Arr3, Arr4
Last edited by SearchingDataOnly; Mar 26th, 2023 at 08:17 PM.
-
Mar 26th, 2023, 08:58 PM
#5
Lively Member
Re: VB6 ADO-Rs-like "multi-column-container"
Hello, olaf
The previous error was indeed caused by using "Rs As AdoDB. Recordset", and it works normally after changing to "Rs As New cRec".
Thank you for your help!
-
May 10th, 2023, 01:33 AM
#6
Lively Member
Re: VB6 ADO-Rs-like "multi-column-container"
Hello Olaf!
In this example, if RC6.cArrayList is not used
“or work with "normal VB-arrays" directly in the cFld-Class”
How to modify the code implementation? Please help implement it.
Thank you very much!
-
May 10th, 2023, 08:01 AM
#7
Re: VB6 ADO-Rs-like "multi-column-container"
Originally Posted by smileyoufu
Hello Olaf!
In this example, if RC6.cArrayList is not used
“or work with "normal VB-arrays" directly in the cFld-Class”
How to modify the code implementation?
You can modify it, starting with the Friend-method: cFld.Init ...(which is called indirectly from cFlds.Append)
There you can store the incoming FldType-param in a class-private internal mFldType-variable.
Then do a:
Select Case mFldType
within the Value-Property Let/Get pair of cFLd
(switching between existing, predefined Private arrays like mLngArr(), mDblArr(), etc. )
In cFld.UpdatePos you will have to do the same Select Case mFldType -
to properly Redim Preserve the right Array-Variable, according to the type...
HTH
Olaf
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|