We help IT Professionals succeed at work.

Structure in vb.net

anusdesai
anusdesai asked
on
2,477 Views
Last Modified: 2013-11-26
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
Comment
Watch Question

TimCotteeHead of Software Services

Commented:
I assume that you have declared RunDetails:

Dim RunDetails() As AutoRunDetails
ReDim RunDetails(20)

For example.

Author

Commented:
Yes,i have done that
 ReDim RunDetails(BatchTotal)
CERTIFIED EXPERT

Commented:
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?
Head of Software Services
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Cheers mate
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.