msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

determining size of data

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
Ken



Joined: 04 Oct 2007
Posts: 7

PostPosted: Mon Jun 18, 2007 8:10 am    Post subject: determining size of data Reply with quote

Hi All,

I have a type as follows

public type Employee
intEmpId as long
sEmpName as string
end type

public emp as Employee

now, i want to know the size of "emp".. is this possible in vb? is it
supports any such function to determine the no of bytes occupied by a "type?"

Thanks

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Norm Cook



Joined: 04 Oct 2007
Posts: 418

PostPosted: Mon Jun 18, 2007 10:55 am    Post subject: Re: determining size of data Reply with quote

"Ken" wrote in message@microsoft.com...
> Hi All,
>
> I have a type as follows
>
> public type Employee
> intEmpId as long
> sEmpName as string
> end type
>
> public emp as Employee
>
> now, i want to know the size of "emp".. is this possible in vb? is it
> supports any such function to determine the no of bytes occupied by a
"type?"
>
> Thanks

Debug.Print Len(emp)
Note that this is the length of the structure/udt, 4 for the long & 4 for
the string
Back to top
View user's profile Send private message
Jim Mack



Joined: 04 Oct 2007
Posts: 735

PostPosted: Mon Jun 18, 2007 1:45 pm    Post subject: Re: determining size of data Reply with quote

Ken wrote:
> Hi All,
>
> I have a type as follows
>
> public type Employee
> intEmpId as long
> sEmpName as string
> end type
>
> public emp as Employee
>
> now, i want to know the size of "emp".. is this possible in vb? is it
> supports any such function to determine the no of bytes occupied by a
> "type?"

What Norm said, but remember that Len() here gives you the length of the string pointer only, not including any string body. In other words, Len() doesn't tell you the length of the data if you write a variable of that type to a file.

--
Jim Mack
MicroDexterity Inc
www.microdexterity.com
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Mon Jun 18, 2007 12:16 pm    Post subject: Re: determining size of data Reply with quote

"Jim Mack" wrote in message @TK2MSFTNGP06.phx.gbl...
>Ken wrote:
>> Hi All,
>>
>> I have a type as follows
>>
>> public type Employee
>> intEmpId as long
>> sEmpName as string
>> end type
>>
>> public emp as Employee
>>
>> now, i want to know the size of "emp".. is this possible in vb? is it
>> supports any such function to determine the no of bytes occupied by a
>> "type?"
>
>What Norm said, but remember that Len() here gives you the length of the
>string pointer only, not including any string >body. In other words, Len()
>doesn't tell you the length of the data if you write a variable of that
>type to a file.

also that it gives the length when used in file i/o operations and not the
actual length in memory;for that use LenB

type x
a as integer
b as long
end type

Len=6
LenB=8 because 2 padding bytes are inserted after the Integer to dword align
the Long
Back to top
View user's profile Send private message
Ken



Joined: 04 Oct 2007
Posts: 7

PostPosted: Thu Jun 21, 2007 7:27 am    Post subject: Re: determining size of data Reply with quote

Hi All

LenB() works!!

Thanks for reply.



"Norm Cook" wrote:

> "Ken" wrote in message
> @microsoft.com...
> > Hi All,
> >
> > I have a type as follows
> >
> > public type Employee
> > intEmpId as long
> > sEmpName as string
> > end type
> >
> > public emp as Employee
> >
> > now, i want to know the size of "emp".. is this possible in vb? is it
> > supports any such function to determine the no of bytes occupied by a
> "type?"
> >
> > Thanks
>
> Debug.Print Len(emp)
> Note that this is the length of the structure/udt, 4 for the long & 4 for
> the string
>
>
>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group