Declaration Expected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eBob.com

    #1

    Declaration Expected

    I've done a lot of programming but very little OOP. Would someone be kind
    enough to explain to me why I get a "declaratio n expected" on this
    statement: anythingarray(0 ) = new anything(3)

    Thanks, Bob

    Public Class Form1

    Inherits System.Windows. Forms.Form

    Dim anythingarray(4 ) As anything

    anythingarray(0 ) = new anything(3) ' < < here's the statement in error

    #Region " Windows Form Designer generated code "



    #End Region

    End Class

    Public Class anything

    Dim onenum As Integer

    Sub New(ByVal x As Integer)

    onenum = x

    End Sub

    End Class


  • tomb

    #2
    Re: Declaration Expected

    Try putting the statement in the Sub New(), or some other function or
    procedure. It looks like it's in the declarations portion.

    Tom

    eBob.com wrote:
    [color=blue]
    >I've done a lot of programming but very little OOP. Would someone be kind
    >enough to explain to me why I get a "declaratio n expected" on this
    >statement: anythingarray(0 ) = new anything(3)
    >
    >Thanks, Bob
    >
    >Public Class Form1
    >
    >Inherits System.Windows. Forms.Form
    >
    >Dim anythingarray(4 ) As anything
    >
    >anythingarray( 0) = new anything(3) ' < < here's the statement in error
    >
    >#Region " Windows Form Designer generated code "
    >
    >
    >
    >#End Region
    >
    >End Class
    >
    >Public Class anything
    >
    >Dim onenum As Integer
    >
    >Sub New(ByVal x As Integer)
    >
    >onenum = x
    >
    >End Sub
    >
    >End Class
    >
    >
    >
    >[/color]

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Declaration Expected

      eBob,

      What you want to do with those statements, even if it was not this error
      that the statements are not correct.

      If it is a try for a redim, than avoid the array, use the arraylist.


      Cor



      Comment

      • Claes Bergefall

        #4
        Re: Declaration Expected

        The conflicting statement needs to be inside a method

        /claes

        "eBob.com" <eBob.com@total lybogus.com> wrote in message
        news:%23kVlKt%2 3bGHA.3352@TK2M SFTNGP03.phx.gb l...[color=blue]
        > I've done a lot of programming but very little OOP. Would someone be kind
        > enough to explain to me why I get a "declaratio n expected" on this
        > statement: anythingarray(0 ) = new anything(3)
        >
        > Thanks, Bob
        >
        > Public Class Form1
        >
        > Inherits System.Windows. Forms.Form
        >
        > Dim anythingarray(4 ) As anything
        >
        > anythingarray(0 ) = new anything(3) ' < < here's the statement in error
        >
        > #Region " Windows Form Designer generated code "
        >
        >
        >
        > #End Region
        >
        > End Class
        >
        > Public Class anything
        >
        > Dim onenum As Integer
        >
        > Sub New(ByVal x As Integer)
        >
        > onenum = x
        >
        > End Sub
        >
        > End Class
        >
        >[/color]


        Comment

        Working...