469,568 Members | 1,498 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

How to get the fixed length of a fixed length string

Private Structure TNavRec

<VBFixedString(100),System.Runtime.InteropServices .MarshalAs(System.Runtime.
InteropServices.UnmanagedType.ByValTStr,SizeConst: =100)> Public strItemName
As String

<VBFixedString(4),System.Runtime.InteropServices.M arshalAs(System.Runtime.In
teropServices.UnmanagedType.ByValTStr,SizeConst:=4 )> Public strItemID As
String

<VBFixedString(2),System.Runtime.InteropServices.M arshalAs(System.Runtime.In
teropServices.UnmanagedType.ByValTStr,SizeConst:=2 )> Public EndOfLine As
String

End Structure

--snip--
Dim ludtNavRec As TNavRec
'accept more than a record will hold
cboName.Text = VB.Left(Value, Len(ludtNavRec.strItemName))

------
In my program
Len(ludtNavRec.strItemName)
returns 0 (probably because I haven't stored anything into it yet).
Probably returning the length of the variable string not the capacity.

I could, of course, store the max length (100) in a const and use that but
I wonder if there is a better way?

Thanks
Nov 20 '05 #1
1 1229
I'd say you have three options - defining a const, only check the len of
structures that have the string fields initialized with strings with the
correct size, or using reflection to pull the attributes and read their
values.
Personally, I'd go either with the constant or with working with correctly
initialized structures only.

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by Adrian Parker | last post: by
3 posts views Thread by Ken Kast | last post: by
5 posts views Thread by David Garamond | last post: by
2 posts views Thread by Frank Swarbrick | last post: by
6 posts views Thread by =?Utf-8?B?TWljaGFlbA==?= | last post: by
2 posts views Thread by =?Utf-8?B?Z3Jva25yb2xs?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.