Solved

Class size in bytes in vb6

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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.
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.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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