1

I have a few User-Defined Types, EG

Public Type Country
    City1 as City
    City2 as City
    City3 as City
End Type
Public Type City
    Name as String
    Buildings as Long
    People as byte
End Type

What I need to do, Is write a function. That is capable of Counting the number of variables in whatever Object I pass into it.

This is going to be for networking optimization. I want to avoid sending Data that is equal to 0 or not set in the case of strings.

My end goal is the Server will Count the variables inside my object, flag which ones are Not 0, and store in a bit-flag byte. Send the Byte or Multiple Bytes to the Client, along with the variables that are not equal to 0.

So I will have a packet that looks like this: Byte() {PacketIDByte,BitFlagBytes(),NotEmptyData()}

The Client has access to the same data, so it can count how many variables the object has and Determine which ones have been sent and need to be set.

Hopefully Im being clear enough, (In this way im hoping to get my 58 * 297 byte Packets Down to around 6to24 * 297 Bytes)

Essentially I need to know How to loop through All properties in an object.

Here a non functioning chunk of code, That I feel illustrates what I am trying to accomplish.

Public Function GetUDTPropertyCount(ByRef AnyObject As Object) As Long
    Dim Obj As Object
    Dim Count As Long
    For Each Obj In AnyObject 'Loop through properties
        If TypeOf Obj Is Object  Then
            Count = Count + GetUDTPropertyCount(Obj)
            GoTo NextObj
        Else 'If typeOf Obj is a value type then
            Count = Count + 1
        End If
NextObj:
    Next Obj
    GetUDTPropertyCount = Count
End Function
Jason Brown
  • 127
  • 2
  • 13
  • Related question: https://stackoverflow.com/questions/547903/self-inspection-of-vb6-udts – andrew Mar 06 '18 at 03:34
  • The related question noted above is probably the way to go. You might have to expose your UDTs as public COM objects to make it work. – StayOnTarget Mar 06 '18 at 12:33
  • Yep, without type information from wrapping the UDTs as IRecord objects all you have are dumb structs. – Bob77 Mar 06 '18 at 19:51
  • Sounds like a pain... I managed to get around it by going a completely different method. – Jason Brown Mar 08 '18 at 05:07

0 Answers0