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