Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3216762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:19:57+00:00 2026-05-17T15:19:57+00:00

I have upgraded some VB6 code, which uses fixed length strings in custom types,

  • 0

I have upgraded some VB6 code, which uses fixed length strings in custom types, to VB .NET by using the UpgradeWizard and am having trouble with the use of the LSet method that I was hoping someone could help me out with.

The Existing VB6 code (type declarations);

Public Type MyType
    PROP1       As String * 15
    PROP2       As String * 25
End Type

Public Type MyTypeBuffer
    Buffer As String * 40
End Type

Example usage;

LSet instOfMyTypeBuffer.Buffer = ...
LSet instOfMyType = instOfMyTypeBuffer

What would be an appropriate way to upgrade this to .NET?

Using the UpgradeWizard, I get the following;

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
 _
Public Structure MyType
    <VBFixedString(15),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=15)> _
    Dim PROP1 As FixedLengthString

    <VBFixedString(25),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=25)> _
    Dim PROP2 As FixedLengthString

    Public Shared Function CreateInstance() As MyType
        Dim result As New MyType
        result.PROP1 = New FixedLengthString(15)
        result.PROP2 = New FixedLengthString(25)
        Return result
    End Function
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
 _
Public Structure MyTypeBuffer
    <VBFixedString(CLVHDR_REC_LENGTH),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=40)> _
    Dim Buffer As FixedLengthString
    Public Shared Function CreateInstance() As MyTypeBuffer
        Dim result As New MyTypeBuffer
        result.Buffer = New FixedLengthString(40)
        Return result
    End Function
End Structure

FixedLengthString is coming from the namespace Microsoft.VisualBasic.Compatibility.VB6.

Where the Upgrade Wizard fails is when it comes to LSet. It produced the following;

instOfMyTypeBuffer.Buffer = LSet(...)
instOfMyType = LSet(instOfMyTypeBuffer)

Which fails to compile, giving these errors;

Value of type ‘String’ cannot be
converted to
‘Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString’

Argument not specified for parameter
‘Length’ of ‘Public Function
LSet(Source As String, Length As
Integer) As String’

Value of type ‘MyTypeBuffer’ cannot be
converted to ‘String’

So, I can use ToString() to get part of the way there, but there is still the issue of the LSet method call itself. What should I do to recreate the original functionality? Has the Upgrade Wizard given me a totally inappropriate conversion, or is it salvageable into something usable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:19:58+00:00Added an answer on May 17, 2026 at 3:19 pm

    LSet is a rather quirky statement in VB6: see description in the manual.

    • When used on strings, it left-aligns the string in the original string and replaces any leftover characters with spaces.
    • When used on user-defined types, it just copies the memory from one user-defined type over the other, even if they had different definitions. This is not recommended.

    It’s being used in a particularly quirky way in the code you have.

    1. LSet instOfMyTypeBuffer.Buffer = ...
      This is redundant both in the VB6 and the migrated Vb.Net. When you assign a new value to a fixed-length string, it always pads out with spaces anyway!
      So just change to this (in either VB6 or VB.Net)
      instOfMyTypeBuffer.Buffer = ...
    2. LSet instOfMyType = instOfMyTypeBuffer
      More interesting. This copies the memory from an instance of one type into an instance of another type, with no checks. Gulp!
      Looking at the definitions of the types, I think this simply puts the first 15 characters from instOfMyBuffer into instOfMyType.PROP1 and the remaining 25 characters into instOfMyType.PROP2.
      I have occasionally seen this used as an ugly way of processing fixed-length string records read from a file. For example the first fifteen characters might be a person’s first name, and the next 25 the last name.
      You could just replace with this code (in either VB6 or VB.Net).
      instOfMyType.PROP1 = Left(instOfMyBuffer.Buffer, 15)
      instOfMyType.PROP2 = Mid(instOfMyBuffer.Buffer, 16)

    Hans suggested ditching the fixed-length strings. If that’s easy – and it depends on the rest of your code base, it might be easy, or it might be hard – it’s good advice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble converting some code from VB6 to VB.NET (I don't have
I have recently upgraded my .Net 3.5 solution containing some C# code projects and
I have a project which I have upgraded to .Net 4.0, but when I
The following code always uses more then ten seconds. I have upgraded the server,
I have recently upgraded some of my web applications to ASP.NET 3.5 by installing
I have recently upgraded from websphere 5.1.2 to websphere 6.1 server. I had some
Have upgraded to eclipse.indigo using a new installation. Added m2e. Maven shows up under
I have upgraded a SQL Server Express 2005 instance to Standard using the best
I have upgraded projects to .net framework 4.0 (VS 2010) and I am getting
All: We are using Visual Studio 2010, and we have recently upgraded our workstations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.