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.

3
  • 1
    question? what do you mean VB6 with an IDE of visual studio 2012 which doesn't support vb6 only vb.net Commented Mar 14, 2014 at 16:23
  • That's my mistake. I meant vb.net on Visual Studio 2012. Commented Mar 14, 2014 at 16:50
  • 2
    Your assignment needs to be in a method Commented Mar 14, 2014 at 16:52

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

That did it, thank you so much. A lot of tutorials and online resources didn't make that clear but this makes sense.

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.