Type to Structure conversion

I have just started using vb.net 2003 and trying to convert an old vb program.  The old defined datatype was:

Type OrderHeader
    InvoiceNo As String * 10
    CustomerNo As String * 6
End Type

I understand that it is now structured like:

Structure OrderHeader
    Private InvoiceNo As String 
    Private CustomerNo As String
End Structure

but since vb.net will not handle a fixed string length is there any way around this

Thanks
Sammy


Answer this question

Type to Structure conversion

  • bopamax

    Convert the structure to a class, and setup property items.



    Public Class OrderHeader
        Private xInvoiceNo As String = Space(10) 'init the string.
        Private xCustomerNo As String = Space(6) 'init the string.

        Public Property InvoiceNo() As String
            Get
                Return xInvoiceNo
            End Get
            Set(ByVal value As String)
                xInvoiceNo = value.Substring(0, 10) 'Limit to the first 10 chars.
            End Set
        End Property
        Public Property CustomerNo() As String
            Get
                Return xCustomerNo
            End Get
            Set(ByVal value As String)
                xCustomerNo = value.Substring(0, 6) 'Limit to the first 6 chars
            End Set
        End Property
    End Class

     


    Dustin.


  • EJG

    Thanks a million Renee.

    Sammy

  • kscdavefl

    Darn ReneeC, you got in just before me.  I didn't know you could set fixed length strings.
    I've always made classes.

    In any case, my class would work too.  Although a little more overhead.  lol
    Dustin.


  • IVRsurveys



     

    Structure GingerBread
       Public Sugar As Integer
       Public Ginger As Long
    <VBFixedString(15)> Public Milk As String
    <VBFixedString(15)> Public Molasses As String
    End Structure


  • ataparia

    Yea, i think your solution is so much... cleaner.  haha



  • sparky62

    You are sooooooooooooooo cool! :)

  • Seth Veale

    Sammy,

    I'm glad I could help. :)


    Dustin,

    To be honest, you've known things that I haven't and I know things that you haven't. That'll continue, I suspect.

    That's why we need each other. :)

    (But jeez, what a complicated solution for a declaration ;)  )



  • Type to Structure conversion