Solved

Attributes Questions...

Posted on 2009-07-09
3
283 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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