Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Attributes Questions...

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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