gbmcneil
asked on
What's wrong with "Public Path As String * 256" in VB.NET 2008?
Hello Experts -
Why doesn't this declaration work?
Public path As String * 256
Why doesn't this declaration work?
Public path As String * 256
VB6 style Fixed-length strings aren't really supported in .Net.
The correct approach really depends in HOW the original string was being used. What is being done in the original app?
The correct approach really depends in HOW the original string was being used. What is being done in the original app?
ASKER
Hi Idle -
I am trying to get someone else's DLL to work in my application and the documentation that was provided included this in the Declarations Section.
I know this form of declaration used to be valid. I'm not misled into thinking that I'm asking the system to multiply a string times a number. See:
http://www.workflowstudios.com/lance/blog.nsf/d6plinks/LSPN-76LLMJ
The question is, if VB.NET no longer allows it, what can I do in its place?
I am trying to get someone else's DLL to work in my application and the documentation that was provided included this in the Declarations Section.
I know this form of declaration used to be valid. I'm not misled into thinking that I'm asking the system to multiply a string times a number. See:
http://www.workflowstudios.com/lance/blog.nsf/d6plinks/LSPN-76LLMJ
The question is, if VB.NET no longer allows it, what can I do in its place?
You can try to substitute a StringBuilder and set its initial length to 256:
Dim sb As New System.Text.StringBuilder( 256)
Dim sb As New System.Text.StringBuilder(
ASKER
Hello Experts -
This is what I really started with:
<StructLayout(LayoutKind.S equential, Pack:=4)> Public Structure gbInfo
Public vol As gbArray
Public oi As gbArray
Public size As Int32
Public datasize As Int32
Public reccnt As Int32
<VBFixedString(256), MarshalAs(UnmanagedType.By ValTStr, SizeConst:=256)> Public path As String
<VBFixedString(16), MarshalAs(UnmanagedType.By ValTStr, SizeConst:=16)> Public name As String
<VBFixedString(48), MarshalAs(UnmanagedType.By ValTStr, SizeConst:=48)> Public description As String
<VBFixedString(16), MarshalAs(UnmanagedType.By ValTStr, SizeConst:=16)> Public symbol As String
Public begindate As Double
Public Function isNull() As Boolean
isNull = dt.isNull
End Function
End Structure
And, the compiler was getting hung up on the strange looking <VBFixedString> " thingies".
So, I pulled the <VBFixedStrings> things and just said, for example:
Public Path As String * 256
But, the compiler doesn't like this declaration either.
This is what I really started with:
<StructLayout(LayoutKind.S
Public vol As gbArray
Public oi As gbArray
Public size As Int32
Public datasize As Int32
Public reccnt As Int32
<VBFixedString(256), MarshalAs(UnmanagedType.By
<VBFixedString(16), MarshalAs(UnmanagedType.By
<VBFixedString(48), MarshalAs(UnmanagedType.By
<VBFixedString(16), MarshalAs(UnmanagedType.By
Public begindate As Double
Public Function isNull() As Boolean
isNull = dt.isNull
End Function
End Structure
And, the compiler was getting hung up on the strange looking <VBFixedString> " thingies".
So, I pulled the <VBFixedStrings> things and just said, for example:
Public Path As String * 256
But, the compiler doesn't like this declaration either.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
You are a genius Idle. Have you ever thought about going on Jeopardy?
Adding the "Imports System.Runtime.InteropServ ices" fixed it.
I guess fixed length strings are supported in VB.NET 2008, if you can get past the unusual way of declaring them!
Thanks.
Adding the "Imports System.Runtime.InteropServ
I guess fixed length strings are supported in VB.NET 2008, if you can get past the unusual way of declaring them!
Thanks.
ASKER
I would not have figured out this one in a million years.
Removing the *256 will allow it to work.
If you are trying to set the length of the path variable to 256 then I don't think you can. You would have to accept the input for path and then use:
path = path.Substring(0, 256)
to cut it down.