?
Solved

Attributes Questions...

Posted on 2009-07-09
3
Medium Priority
?
289 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 400 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 1600 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 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