2

I'm hitting the following issue in this simple code:

Public Class BookStoreDatabase

Public publicationArray(0 To 3) As String

publicationArray(0) = "Stories to Scare People With"
End Class

The bit "publicationArray(0) etc" is telling me that a declaration for "publicationArray" is expected. This seems like it shouldn't be happening.

Crono
  • 10,211
  • 6
  • 43
  • 75
Brocktoon
  • 63
  • 1
  • 7

1 Answers1

2

You cannot assign a array element at Class level. If you need it to be assigned as soon as the BookStoreDatabase class itself is instantiated, you must use a constructor:

Public Class BookStoreDatabase

    Public Sub New()
        publicationArray(0) = "Stories to Scare People With"
    End Sub

    Public publicationArray(0 To 3) As String

End Class
Crono
  • 10,211
  • 6
  • 43
  • 75
  • That did it, thank you so much. A lot of tutorials and online resources didn't make that clear but this makes sense. – Brocktoon Mar 14 '14 at 18:48