Solved

Class size in bytes in vb6

Posted on 2008-10-12
4
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

617 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