veayou
asked on
What is the syntax to make a string variable fixed?
Please help!
The String data type in vb.net can store up to 2 GBs and we can just create a variable like this:
dim str as string
But now I would like to make this str to be fixed. I got the syntax like this:
<vbFixedstring(10)> dim str as string
str = "This is for testing."
msgbox (str)
By writing like this I can still assign value more than 10 characters and can call it back as well without losing any character.
What is the problem? and do you have any syntax?
Thank you.
BM
maybe look here
http://www.mentalis.org/vbtutor/vbdotnet.shtml
if you need the fixed lenght string as a parameter for an Api call, you could use this
Dim sBuf As String = Space(128)
http://www.mentalis.org/vbtutor/vbdotnet.shtml
if you need the fixed lenght string as a parameter for an Api call, you could use this
Dim sBuf As String = Space(128)
this is from the Help system overfied on vbFIxedString:
"Note The VBFixedStringAttribute is informational and cannot be used to convert a variable length string to a fixed string. The purpose of this attribute is to modify how strings in structures and non-local variables are used by methods or API calls that recognize the VBFixedStringAttribute. Keep in mind that this attribute does not change the actual length of the string itself."
The last sentence seems to be quite clear that this attribute DOES NOT do what you seem to think it does.
.NET does NOT support Fixed length strings.
AW
"Note The VBFixedStringAttribute is informational and cannot be used to convert a variable length string to a fixed string. The purpose of this attribute is to modify how strings in structures and non-local variables are used by methods or API calls that recognize the VBFixedStringAttribute. Keep in mind that this attribute does not change the actual length of the string itself."
The last sentence seems to be quite clear that this attribute DOES NOT do what you seem to think it does.
.NET does NOT support Fixed length strings.
AW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oeps, sorry arthur_wood I should learn to refresh before I post
ASKER
I can see now. <vbFixedString> can not be used.
I have tried the code below but it's not work again:
dim str as string = space(5)
str = "1234567 56 33 4 5 6 4 2 3 3 4 45 "
Msgbox (str)
Result:
1234567 56 33 4 5 6 4 2 3 3 4 45
Maybe in VB.Net we can not make a string variable fixed....????
BM.
No you can't make a fixed lenght string it is not supported by .net, the example I gave is for if you need to simulate a fixed lenght string for use in an API. You will still be able to change the lenght afterwards
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my bad it should be
with str
.SetMaxLength 8
.SetString "This Is Longer than eight characters"
end with
Corey
with str
.SetMaxLength 8
.SetString "This Is Longer than eight characters"
end with
Corey
str = "This is for testing."
str = str & "More added"