 |
| VB How-To Ask your "How do I do this with VB?" questions in this forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 19th, 2006, 01:09 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
UserType Variables--loop thru their names?
How can I loop thru a user type and look at their names?
e.g.-- in simplified form---
Public Type txx
xxAA As Integer
xxBB As Integer
xxCC As Integer
xxDD As Integer
End Type
Sub do_tst()
Dim axx As txx
Dim e As element, ii As Integer
For ii = 0 To axx.elements.Count - 1
If axx.element(ii).Name = "xxBB" Then
axx.element(ii).Value = ii
End If
Next ii
End Sub
tkx, Paul
|
|

November 19th, 2006, 01:17 PM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
|

November 20th, 2006, 02:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sorry you can't
in VB you can get that capability using a Collection or a Dictionary (using the Key property) or a disconnected RecordSet (using the Field name)
|
|

November 20th, 2006, 04:02 PM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well.
Depending on what you are really trying to do, you can use the TypeLib information object library to inspect com objects and the members within them.
This is a bit of work, and might not really be what you want, but it could be worth looking into.
Here is a little sample of the idea.
Code:
Private Sub Command1_Click()
Dim oTypeLibInfoApp As TLIApplication
Dim oTypeLibeInfo As TypeLibInfo
Dim oTypeInfo As TypeInfo
Dim oMemberInfo As MemberInfo
Set oTypeLibInfoApp = New tli.TLIApplication
Set oTypeLibeInfo = oTypeLibInfoApp.TypeLibInfoFromFile("c:\TlibTests.dll")
Set oTypeInfo = oTypeLibeInfo.GetTypeInfo("EnumTest")
If Not oTypeInfo Is Nothing Then
For Each oMemberInfo In oTypeInfo.Members
Debug.Print oMemberInfo.Name, oMemberInfo.Value
Next
End If
End Sub
Woody Z http://www.learntoprogramnow.com
|
|

November 24th, 2006, 09:09 PM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Woody Z,
Thanks for the 2nd response. It contains a possible direction.
But it seems not to work in my environment.
I am running MS-Access2000--VBA/Access6.0,version8714.
I have tried variations on the line -- "Set oTypeLibeInfo = oTypeLibInfoApp.TypeLibInfoFromFile("c:\TlibTests. dll")"
by changing the file to "H:\vba\log_data_analysis.mdb"
which is my program.
This results in a tlib structure, but all counts are ZERO--
CoClasses, Constants, CustomDataCollections, Declarations,
Interfaces, IntrinsicAliases, Records, TypeInfos, Unions.
And thus I get no valid information.
I suspect that tlbinf32.dll doesn't work on MS-Access-mdb-s.
Any other suggestions?
tkx, Paul
|
|

November 25th, 2006, 02:25 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Paul Gerken
Hi Woody Z,
Thanks for the 2nd response. It contains a possible direction.
But it seems not to work in my environment.
I am running MS-Access2000--VBA/Access6.0,version8714.
I have tried variations on the line -- "Set oTypeLibeInfo = oTypeLibInfoApp.TypeLibInfoFromFile("c:\TlibTests. dll")"
by changing the file to "H:\vba\log_data_analysis.mdb"
which is my program.
This results in a tlib structure, but all counts are ZERO--
CoClasses, Constants, CustomDataCollections, Declarations,
Interfaces, IntrinsicAliases, Records, TypeInfos, Unions.
And thus I get no valid information.
I suspect that tlbinf32.dll doesn't work on MS-Access-mdb-s.
Any other suggestions?
tkx, Paul
|
You need to point at an exe or dll that exposes COM classes. Without that, the Type Library functions wont work. Since I don't know your purpose for doing what you want to do, it is hard to suggest anything. One purpose for an enum is to provide a type that contains human readable names for constant integer values that are related in purpose - this helps solve the problem of "magic numbers" in the code, and gives us a way to work with these values in code using intelisense and code completion. Most of the time when I see code that needs to get at the names used in the enum it is a red flag that the enum is being used for more than it was invented for.
That being said, if there is some legitimate reason to need this in your code you can provide a reverse look-up function that returns the name (as a string) for any enum member passed in. These are typically coded using a Select Case block, but can also be done with a collection.
Again - it is rare that there is a legitimate need for this type of functionaltiy.
Woody Z http://www.learntoprogramnow.com
|
|

November 25th, 2006, 08:49 PM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Woody Z,
I have 400,000+ rows of student transcript info, that is accessed by SQL with joins and unions. This SQL is for research into grades and college readiness, and other columns are added and deleted over time.
I would like to decouple the SQL column number of the data from the Processing column number. The initialization section of the processing would loop thru the RecordSet.Field(ii).Name and match these with the UserDefinedType field names, and set the column number index where found.
The rest of the processing would look at the transcript items for each student, and calculate various groupings, depending on which column
has the data for this run, by using the index value found in the instantiated UDT.
>> How can I loop thru a user type and look at their names? <<
Back to my original question--
Were I to use a Select/Case block, I would need to also have a DIM.
And over time when additional variables are introduced, then would make modifications in two places--another DIM and another CASE.
With a UserDefinedType, I only need to add another field as Integer.
Yes, the intended use is legitimate, maybe rare, or you just haven't
seen it before (aka NIH).
So, what kind of EXE or DLL is needed to expose the COM classes
that are in my MDB? Not the "txx" UDT, but the "axx" instantiation of it. I didn't find that the tlbinf32 is able to get anything from my mdb. Do I need to create an EXE out of my MDB? How is that done?
Any further ideas?
tkx, Paul
|
|

November 26th, 2006, 12:27 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I do not know of any way to make an EXE or DLL from the mdb. As far as I know, that is not an avenue that is worth pursuing.
As I now understand what you need it is to populate a UDT with values from a record by dynamically matching the name of the member of the UDT with the name of the column.
There is no easy way to do this in VB6. I don't have much direct experience programming directly in Access - but if you were to try to use the typlib classes to do this you would have to move the UDTs out of your Access app into a VB6 com component, and then reference that component in your Access app. However, I really think this is not a reasonable approach. You could experiment with it, but overall I think you will find it is not worth the effort - even though it seems reasonable to do.
This sort of thing is typically done with a mapping mechanism, such as I described earlier. There are many other ways to do this sort of mapping - my little suggestion is just one way to do it.
Is it necessary that a UDT be used rather than a class?
Woody Z http://www.learntoprogramnow.com
|
|

November 27th, 2006, 02:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sorry, but I really do not understand what you want to do (pardon me please), expecially the phase "I would like to decouple the SQL column number of the data from the Processing column number."
I do something similar: a get a recordset and I use it to populate a MSFlexGrid, using the "Name" property of the Field as the column header. So when I click in any column I know which field I am pointing (using the header in the matrix). In this way I do not have anything hardcoded, I do not use the column "number" but the field name, and I can load any recordSet I want.
let me know if I am completely off track here
|
|

December 4th, 2006, 12:13 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi marcostraf,
Thanks for your efforts. I have used that in other situations.
In this case I populate a 2-D array via GetRows until I get to the
end of a key. Then I process all the rows in the array to compute
several results, e.g.
For rr = 1 to maxRows
aSum = aSum + anArray(rr,axx.xxBB)
next rr
Sometimes my "BB" data is in column 2, other times in column 3 or 6...
During the initialization phase, I want to read the rst.Field(cc).Name
and match that name to the txx.element(jj).Name
and set the txx.element(jj).Value equal to cc.
Since I am not finding any solution to this on this forum,
I think that I need to say--Thanks to all, and bye.
|
|
 |