Home > Archive > Visual Basic > January 2006 > Ascertain number of fields in a user defined type
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Ascertain number of fields in a user defined type
|
|
| Carl Imthurn 2006-01-27, 6:56 pm |
| Is there a way to ascertain at run time how many "fields" are in a particular user-defined type?
For example:
Public Type DrugSummaryItem
ProcedureNumber As String
HowMany As Integer
End Type
Public DrugSummaryArray() As DrugSummaryItem
How do I ascertain that the array DrugSummaryArray() has exactly 2 fields in it?
And, even better, what data type they are?
Thanks in advance --
Carl Imthurn
| |
| Ken Halter 2006-01-27, 6:56 pm |
| "Carl Imthurn" <nospam@all.com> wrote in message
news:OspWiL4IGHA.648@TK2MSFTNGP14.phx.gbl...
> Is there a way to ascertain at run time how many "fields" are in a
> particular user-defined type?
>
No way that I've heard of... unless it's a Public type and you're using
tlbinf32.dll to query its interfaces. If that's the case, it'll show the
members and types just like VBs Object Browser does (since tlbinf32.dll is
what the Object Browser uses to inspect components)
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
| |
| Dmitriy Antonov 2006-01-27, 9:55 pm |
|
"Carl Imthurn" <nospam@all.com> wrote in message
news:OspWiL4IGHA.648@TK2MSFTNGP14.phx.gbl...
> Is there a way to ascertain at run time how many "fields" are in a
> particular user-defined type?
>
> For example:
>
> Public Type DrugSummaryItem
> ProcedureNumber As String
> HowMany As Integer
> End Type
>
> Public DrugSummaryArray() As DrugSummaryItem
>
> How do I ascertain that the array DrugSummaryArray() has exactly 2 fields
> in it?
> And, even better, what data type they are?
>
> Thanks in advance --
>
> Carl Imthurn
>
Perhaps I don't understand the task, but, I would say, it is guaranteed by
compiler. So it is ascertained "by definition". So it will always have the
number of members and their types as it was declared and there is no way to
do it otherwise. What else you need to ascertain?
Dmitriy.
| |
| Carl Imthurn 2006-01-30, 6:55 pm |
| Thank you both for your replies -- here's some additional information
that I should have included in the initial post -- my apologies . . .
I am populating a data entry form from one of nine arrays. Each array contains a user-defined type as follows:
> Public Type DrugSummaryItem
> ProcedureNumber As String
> HowMany As Integer
> End Type
>
> Public DrugSummaryArray() As DrugSummaryItem
Each user-defined type contains between 2 and 5 fields. Those fields could be string or date datatype.
What is the possibility of determining the number of fields/columns in a UDT so that I would know
how many controls to put on the data entry form? I can hard-code a value in a table, but if it could be
determined at runtime that would be great.
Thanks again --
Carl
| |
| Lance Wynn 2006-01-30, 6:55 pm |
| Hi,
I was intrigued by this, and I know that it is done within the Soap toolkit
to create the WSDL from a COM component. I'm not sure if this is how they
do it, but I was able to use the following code to interrogate the dll, find
UDTs, and List their elements with datatypes. you need to create a
reference to the TypeLib Information library, and then just paste this code,
and run the test sub. You'll want to add error handling, and all, but maybe
this will get you started.
Lance
Option Explicit
Function TypeLibUDTs(sFileName As String) As Variant
Dim oTypeLib As TLI.TypeLibInfo
Dim oTypeInfo As TLI.TypeInfo
Dim i As Long, j As Long
Set oTypeLib = CreateObject("TLI.TypeLibInfo")
oTypeLib.ContainingFile = sFileName
If oTypeLib.TypeInfoCount Then
For i = 1 To oTypeLib.TypeInfoCount
Set oTypeInfo = oTypeLib.TypeInfos(i)
If oTypeInfo.TypeKind = TKIND_RECORD Then
Debug.Print "---UDT found: " & oTypeInfo.Name
For j = 1 To oTypeInfo.Members.Count
Debug.Print "UDT Element Name: " & oTypeInfo.Members(j).Name
Debug.Print "UDT DataType : " &
oTypeInfo.Members(j).ReturnType.VarType
Next
End If
Next
End If
Set oTypeLib = Nothing
End Function
Sub Test()
TypeLibUDTs "c:\UDTTypeLibTest.dll"
End Sub
"Carl Imthurn" <nospam@all.com> wrote in message
news:ObEZpAbJGHA.3944@tk2msftngp13.phx.gbl...
Thank you both for your replies -- here's some additional information
that I should have included in the initial post -- my apologies . . .
I am populating a data entry form from one of nine arrays. Each array
contains a user-defined type as follows:
> Public Type DrugSummaryItem
> ProcedureNumber As String
> HowMany As Integer
> End Type
>
> Public DrugSummaryArray() As DrugSummaryItem
Each user-defined type contains between 2 and 5 fields. Those fields could
be string or date datatype.
What is the possibility of determining the number of fields/columns in a UDT
so that I would know
how many controls to put on the data entry form? I can hard-code a value in
a table, but if it could be
determined at runtime that would be great.
Thanks again --
Carl
| |
| Carl Imthurn 2006-01-30, 6:55 pm |
| Wow.
Thanks Lance - I really appreciate the time you took to do this.
I will check it out as soon as I can and report back.
Carl
Lance Wynn wrote:
> Hi,
>
> I was intrigued by this, and I know that it is done within the Soap toolkit
> to create the WSDL from a COM component. I'm not sure if this is how they
> do it, but I was able to use the following code to interrogate the dll, find
> UDTs, and List their elements with datatypes. you need to create a
> reference to the TypeLib Information library, and then just paste this code,
> and run the test sub. You'll want to add error handling, and all, but maybe
> this will get you started.
>
> Lance
>
> Option Explicit
>
> Function TypeLibUDTs(sFileName As String) As Variant
> Dim oTypeLib As TLI.TypeLibInfo
> Dim oTypeInfo As TLI.TypeInfo
> Dim i As Long, j As Long
>
> Set oTypeLib = CreateObject("TLI.TypeLibInfo")
> oTypeLib.ContainingFile = sFileName
>
> If oTypeLib.TypeInfoCount Then
> For i = 1 To oTypeLib.TypeInfoCount
> Set oTypeInfo = oTypeLib.TypeInfos(i)
> If oTypeInfo.TypeKind = TKIND_RECORD Then
> Debug.Print "---UDT found: " & oTypeInfo.Name
> For j = 1 To oTypeInfo.Members.Count
> Debug.Print "UDT Element Name: " & oTypeInfo.Members(j).Name
> Debug.Print "UDT DataType : " &
> oTypeInfo.Members(j).ReturnType.VarType
> Next
> End If
> Next
> End If
>
> Set oTypeLib = Nothing
>
>
> End Function
>
> Sub Test()
> TypeLibUDTs "c:\UDTTypeLibTest.dll"
> End Sub
>
>
>
> "Carl Imthurn" <nospam@all.com> wrote in message
> news:ObEZpAbJGHA.3944@tk2msftngp13.phx.gbl...
> Thank you both for your replies -- here's some additional information
> that I should have included in the initial post -- my apologies . . .
>
> I am populating a data entry form from one of nine arrays. Each array
> contains a user-defined type as follows:
>
>
> Each user-defined type contains between 2 and 5 fields. Those fields could
> be string or date datatype.
> What is the possibility of determining the number of fields/columns in a UDT
> so that I would know
> how many controls to put on the data entry form? I can hard-code a value in
> a table, but if it could be
> determined at runtime that would be great.
>
> Thanks again --
>
> Carl
>
>
|
|
|
|
|