Solved

Class size in bytes in vb6

Posted on 2008-10-12
4
352 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

759 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

22 Experts available now in Live!

Get 1:1 Help Now