Solved

Attributes Questions...

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now