Click here to Skip to main content
14,836,727 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Public Class Form1
    Dim List(15) As Record

    Structure Record

        Dim Caption As String
'may be i cant do that anyone help me??
        Dim Accounts() As SturAccount

    End Structure

    Structure SturAccount
        Dim Name As String
        Dim Pw As String
    End Structure

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim EachAccounts(4) As SturAccount

        EachAccounts(0).Name = "123"
        EachAccounts(0).Pw = "123"

        EachAccounts(1).Name = "fai"
        EachAccounts(1).Pw = "789"

        For i As Integer = 0 To 1
            List(i).Caption = 10
            For j As Integer = 0 To 1
                   'Error here. i dont know why.
              List(i).Accounts(j).Name = EachAccounts(j).Name
             List(i).Accounts(j).Pw = EachAccounts(j).Pw
    End Sub
End Class
Updated 13-Jun-11 22:14pm

1 solution

If you told us what the error was, it would help. But, I'd say that Accounts(j) is null and needs to be created before you can set values on it.
faifai2 14-Jun-11 4:23am
Error occur on this Line.
List(i).Accounts(j).Name = EachAccounts(j).Name

i dont know why.
however, may be the accounts had not declared the size.
Dave Kreskowiak 14-Jun-11 8:25am
Yes, that's the problem. You didn't create the array inside the structure. In order to store sata in it, the array has to have dimensions.

Personally, I'd scrap the arrays altogether and go with a couple of List(Of ...) instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900