Structure in

Posted on 2007-10-05
Last Modified: 2013-11-26
How do i convert this code from vb 6.0 to

Type AutoRunDetails
    Name As String
    doControls As Boolean
    ReportTotal As Integer
    ReportType(1 To 20) As String
    ReportName(1 To 20) As String
End Type

Also how do add values in it

example vb 6.0
    RunDetails(BatchNo).ReportType(RptCount) = "RI"

but if i do the same in
Structure AutoRunDetails
            Dim Name As String
            Dim doControls As Boolean
            Dim ReportTotal As Short
            <VBFixedArray(20)> Dim ReportType() As String
            <VBFixedArray(20)> Dim ReportName() As String            
            Public Sub Initialize()
            ReDim ReportType(20)
            ReDim ReportName(20)
            End Sub
      End Structure
      RunDetails(BatchNo).ReportType(RptCount) = "RI"

i get error object not set to reference
Question by:anusdesai
    LVL 44

    Expert Comment

    I assume that you have declared RunDetails:

    Dim RunDetails() As AutoRunDetails
    ReDim RunDetails(20)

    For example.

    Author Comment

    Yes,i have done that
     ReDim RunDetails(BatchTotal)
    LVL 25

    Expert Comment

            <VBFixedArray(20)> Dim ReportType() As String
                <VBFixedArray(20)> Dim ReportName() As String      
                Dim ReportType(20) As String
                Dim ReportName(20) As String      
    if you want two fixed arrays with 20 elements.

    You cannot change instance data from within a method in a struct.  You can only change static data.

    If you want to do this sort of thing, why not just use  a class and the constructor?
    LVL 44

    Accepted Solution

    Not having tried this before I assumed that it would be easier than it actually is. Why on earth it is more complicated in .Net than VB6 I do not know. Anyway here is a workable solution to the issue:

        Structure AutoRunDetails
            Public Name As String
            Public doControls As Boolean
            Public ReportTotal As Short
            Public ReportType() As String
            Public ReportName() As String
            Public Sub New(ByVal Length As Integer)
                Length = 20
                ReDim ReportType(Length)
                ReDim ReportName(Length)
            End Sub
        End Structure


            Dim RunDetails(20) As AutoRunDetails
            For I As Integer = 0 To RunDetails.GetUpperBound(0)
                RunDetails(I) = New AutoRunDetails(20)
            RunDetails(12).ReportType(10) = "RI"
            RunDetails(20).ReportType(10) = "RI"

    For example, this initialises the arrays when each element of the RunDetails() array is scanned. It then works as you would expect.

    Not a nice implementation perhaps but it seems to be the only way of doing it, all the obvious shortcuts e.g.,

    Dim RunDetails() As AutoRunDetails = New AutoRunDetails(20)

    Etc don't seem to work whereas this does.

    Author Comment

    Cheers mate

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Build VS2015 project in bat command 3 54
    WS_CHILD window 14 36
    vb linq Count Distinct? 1 29
    Problem to event 3 27
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now