Create a table in a class that inherits from another class?

Didier T

New member
Joined
May 4, 2021
Messages
1
Programming Experience
Beginner
I've been battling for some times now with a little problem which I think has a very easy solution; but can't find it. Maybe I couldn't get the right way to formulate my question on Google... Anyways, I went around it but the way I've done it is very inelegant and cumbersome. What I really want to do would be something like this:


VB.NET:
Public Class Form1
    Public Class my_classOne
        Public the_name As String = ""
        Public the_surname As String = ""
    End Class

    Public Class my_classTwo
        Inherits my_classOne
        Public a_table(10) As my_classOne
        Public a_thing As New my_classOne
    End Class


    Public the_record As New my_classTwo

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim i As Integer
        For i = 1 To 10
            the_record.a_table(i).the_name = "Name is:" + i.ToString
            Label1.Text = the_record.a_table(i).the_name
            the_record.a_thing.the_name = "Name: " + i.ToString
            Label1.Text = the_record.a_thing.the_name
        Next
    End Sub
    End Class


I get, when debugging, the error shown in the picture on that line of code:

the_record.a_table(i).the_name = "Name is:" + i.ToString



What do I do wrong? How can I get `a_table()` in `my_classTwo` to inherit from `my_classOne`?

As I read so unpleasantly in another place; I'm not looking for somebody to write my code; only somebody to tell me where my error is; how I can fix it and then I will do the research. And I'm a beginner so keep the explanation simple? Thanks :)

error.jpg
 
So we meet again, and you have chosen to ignore absolutely everything I told you at Stack Overflow and have clearly made no effort to do any research on using arrays. How many times can I tell you the same thing? If you don't put anything into the array then you can't get anything out. Where exactly in that code do you think you're putting something into that array? Have you made any effort to find out how to use arrays, because there's no evidence of it here? If you wrote this code:
VB.NET:
Public Class Thing

    Public Property Text As String
   
End Class
and then this:
VB.NET:
Dim t As Thing

t.Text = "Hello World"

Console.WriteLine(t.Text)
what would you expect to happen?
 
Back
Top