Home All Groups Group Topic Archive Search About

using user defined types

Author
23 May 2005 6:38 PM
Dave
I have a udt set up and a collection that I add the udts to throughout a
program. Then, at the appropriate time, I would like to loop through the
collection and send each udt in it to a subroutine to be processed. I had
though it would be done as follows but have several problems, as you can
probably see. One is to cast the collection item to the AuthInfo type, and
the other is to pass the AuthInfo item into the subroutine.

Can some one give me some guidance on the use of collections for this in
VB6?

Thanks in advance fro your help.

Dave

Public Type AuthInfo
    scanSO As String
    tndSO As String
    authLevel As Long
    authOperator As String
    operLevel As Long
    authTime As Date
End Type

Public g_udtAuthCol As Collection

private sub somesub()
    dim audt as AuthInfo
    with audt
        .scanSO = "something"
        .
        .
    end with
    g_udtAuthCol.Add(audt)
end sub

private sub finishup()
    dim anEvent as AuthInfo
    dim lpc as integer
    for lpc = 0 to g_udtAuthCol.Count -1
        anEvent = g_udtAuthCol.Item(lpc)
        processEvent(anEvent)
    next
end sub

private processEvent(e as AuthInfo)
    'do stuff to e here
end sub

Author
23 May 2005 9:20 PM
Mike D Sutton
> I have a udt set up and a collection that I add the udts to throughout a
> program. Then, at the appropriate time, I would like to loop through the
> collection and send each udt in it to a subroutine to be processed. I had
> though it would be done as follows but have several problems, as you can
> probably see. One is to cast the collection item to the AuthInfo type, and
> the other is to pass the AuthInfo item into the subroutine.
>
> Can some one give me some guidance on the use of collections for this in
> VB6?
<code snipped>

UDT's cannot be stored in collections (unless they're declared externally from your application), either use an array
for this instead or better still, write your own AuthInfo collection object which just uses a dynamic array internally.
This object could also include the functionality to process each UDT in the collection, a much neater solution IMO.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
25 May 2005 12:51 PM
Dave
Thank you Mike, I appreciate the suggestion.

Dave

Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:%23oAcC19XFHA.2588@TK2MSFTNGP14.phx.gbl...
>> I have a udt set up and a collection that I add the udts to throughout a
>> program. Then, at the appropriate time, I would like to loop through the
>> collection and send each udt in it to a subroutine to be processed. I had
>> though it would be done as follows but have several problems, as you can
>> probably see. One is to cast the collection item to the AuthInfo type,
>> and
>> the other is to pass the AuthInfo item into the subroutine.
>>
>> Can some one give me some guidance on the use of collections for this in
>> VB6?
> <code snipped>
>
> UDT's cannot be stored in collections (unless they're declared externally
> from your application), either use an array
> for this instead or better still, write your own AuthInfo collection
> object which just uses a dynamic array internally.
> This object could also include the functionality to process each UDT in
> the collection, a much neater solution IMO.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>