Solved

Attributes Questions...

Posted on 2009-07-09
3
288 Views
Last Modified: 2013-11-26
<VBFixedString(10)> Private sID As String

What does <VBFixedString(10)> mean?

Please explain to me what attributes does?

What is the difference on having an attribute and not having an attributes?

For example:

If I declare something like this:

<VBFixedString(10)> Private sID As String

What is the difference, of above code to this?

Private sID As String


Please avoid posting some links...

:)
0
Comment
Question by:JackOfPH
[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
3 Comments
 
LVL 18

Assisted Solution

by:philipjonathan
philipjonathan earned 100 total points
ID: 24820473
It means that the string is treated as fixed length string. Fixed length string is similar to Pascal style string variables. The string is stored as 2 bytes (the length), followed by the string content. The VBFixedString attribute is used by FileGet and FilePut functions to read and write string to file.

I try to avoid posting links, but I think these could give you better picture:
http://social.msdn.microsoft.com/Forums/en-US/vbinterop/thread/e9b0e85b-2f3a-4be0-b65d-f7c6de89d7d7
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.vbfixedstringattribute.aspx
http://msdn.microsoft.com/en-us/library/3acfheek.aspx
0
 
LVL 13

Accepted Solution

by:
kaylanreilor earned 400 total points
ID: 24820495
Alone it has no sense to use this attribute. It is used to build a structure actually so that you can concatane data.
The problem that this attribute solves is created by the fact that in VB.NET, a string has the characteristics of an array of Char instances. (An array of Chars, in other words.)
When you create a file using a structure containing strings and VB.NET's FilePut, you don't get what you might expect because VB.NET puts in extra information because it's an array of Chars. Consider this example program. (PrefixString and PostfixString are there just to provide a visual marker in the created file.)
Structure VariableType
    Public PrefixString As String
    Public myString As String
    Public PostfixString As String
End Structure

Private Sub Button1_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles Button1.Click
    Dim myRecord As VariableType
    FileOpen(1, "F:\TESTFILE.TXT", _
        OpenMode.Binary)
    myRecord.PrefixString = "X"
    myRecord.myString = "AAAAA"
    myRecord.PostfixString = "X"
    FilePut(1, myRecord)
    FileClose(1)
End Sub
When the resulting program is executed, here's what the file looks like in Notepad (attached screenshot). To solve this problem, the structure is changed by adding the VBFixedString attribute. (Dim myRecord As FixedType must also be changed.)
Structure FixedType
    <VBFixedString(1)> Public PrefixString As String
    <VBFixedString(5)> Public myString As String
    <VBFixedString(1)> Public PostfixString As String
End Structure

I think you really should read this : http://visualbasic.about.com/od/usingvbnet/a/apporg01_3.htm
notepadResult.JPG
0
 
LVL 15

Author Closing Comment

by:JackOfPH
ID: 31601939
It is nice that someone cares to explain this to me... :)
Thanks to both of you...

God Bless...

:)
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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