Link to home
Start Free TrialLog in
Avatar of anusdesai
anusdesai

asked on

Structure in vb.net

Hi,
How do i convert this code from vb 6.0 to vb.net

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 vb.net
by:
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
code:
      RunDetails(BatchNo).ReportType(RptCount) = "RI"

i get error object not set to reference
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

I assume that you have declared RunDetails:

Dim RunDetails() As AutoRunDetails
ReDim RunDetails(20)

For example.
Avatar of anusdesai
anusdesai

ASKER

Yes,i have done that
 ReDim RunDetails(BatchTotal)
Avatar of SStory
change
        <VBFixedArray(20)> Dim ReportType() As String
            <VBFixedArray(20)> Dim ReportName() As String      
to        
            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?
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cheers mate