Solved

Class size in bytes in vb6

Posted on 2008-10-12
4
354 Views
Last Modified: 2013-11-25
If I have the following class:
Class1
Private strFName as string
Private strLName as string

Class1_Initialize()
strFName = ""
strLNAme = ""

Public Sub SetValues(byval FirstName as string, byval LastName as string)
strfName= FirstName
strLANme = LastName
End Sub

Public Property Get FullName() as string
FullName = strfName & " " & strLName
End Property

As you can see, I can initialize the class:
Dim cthis as new Class1
cthis.SetValues "Armando", "Ruiz"

now, my question is: I want to send this class(object) by winsock and udp or tcp protocol, how do i determine the size in bytes of my class?
0
Comment
Question by:Aruiz04
  • 2
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 22702730
The size in bytes is the size of the properties.  Assuming you are not transmitting unicode, it would be something like this.

If you are using Unicode, you would want to use the LenB function instead.

When you are actually sending, you may have to add spacers so that you can tell one string from the next.  Chr(0) would be the obvious choice, but remember this will add to the length of the transmission.
Public Function GetSize() As Long

    GetSize = Len(strFName) + Len(strLName)

End Function

Open in new window

0
 
LVL 5

Author Comment

by:Aruiz04
ID: 22707692
Thanks for your help. Your answer sure makes sense, I appreciate it. Assuming that I have functions and Private subs within the class, Do I still have to add those private variables even if they are not counted as properties? What I'm trying to do is send my own class(object) by winsock, either by tcp or udp. When I send the class it does not raise errors, but when I try to convert and assign at the receiving point just does not work.
Any comments or pointers are apreciated.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 22736773
>When I send the class it does not raise errors

What code are you using to do this?
0
 
LVL 5

Author Comment

by:Aruiz04
ID: 22763748
I think I'm making it more difficult than it should be. I have the idea of sending messages and split the message at the receiving point, the string I think i need to send should have an index, which at the receiving point should know what to do and where to store it, ie If the index I send is 0, it should create a new instance of the class itself, and for 1 and up, should be assigned to any other property of the class. I think that in this manner I should be able to make them understand each other the sending point and the receiving end. by the way i'm not ignoring you answer, it has been very helpful. Somehow I was thinking that the class itself would claim memory size by declaring variables in private routines. I forgot that I have to think about the scope of those variables, they execute and they "die".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now