Solved

Class size in bytes in vb6

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.

773 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