0

I am trying to us a Type within another type but it is not letting me.

Public Type MyTable
     Name As String
     IDStartingNumber As Integer
     Items(50) As MyItem
End Type

Public Type MyItem
    Name As String
    DataType As DataTypes
    Number As Integer
    AllowNull As Boolean
    Unique As Boolean
    Reference As MyTable
End Type

What is going on and how do I fix this?

2
  • What error do you get? Commented Jul 7, 2013 at 2:42
  • "Compile Error: Forward reference to user-defined type" Commented Jul 7, 2013 at 2:44

2 Answers 2

6

Make sure the type you're referencing is before it. In your example you have the MyItem type afterwards. For example:

Public Type MyItem
    Name As String
    DataType As DataTypes
    Number As Integer
    AllowNull As Boolean
    Unique As Boolean
    Reference As MyTable
End Type

Public Type MyTable
     Name As String
     IDStartingNumber As Integer
     Items(50) As MyItem
End Type
Sign up to request clarification or add additional context in comments.

Comments

0

In both examples, it appears one type references the other, so neither example should work.

i.e.

Public Type MyTable Name As String IDStartingNumber As Integer Items(50) As MyItem End Type

Public Type MyItem Name As String DataType As DataTypes Number As Integer AllowNull As Boolean Unique As Boolean Reference As MyTable End Type

You cannot have one type refer to a different type which refers back to the first type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.