ItemTypes' is not accessible in this context because it is 'Privat

Discussion in 'ASP .Net' started by =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 5, 2004.

  1. Hi,
    I declared ItemTypes as:-
    Dim ItemTypes As New ArrayList
    Outside the Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load and have a function that refs it:-
    Function SetIndex(ByVal TheItem As String)
    Dim i As Integer
    For i = 0 To ItemTypes.Count - 1
    If TheItem = ItemTypes(i) Then
    Return i
    End If
    Next
    End Function
    WHat could cause THIS ERROR?
    Any ideas!
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 5, 2004
    #1
    1. Advertising

  2. Hi,

    See inline:

    "Patrick.O.Ige" <> wrote in message
    news:...
    > Hi,
    > I declared ItemTypes as:-
    > Dim ItemTypes As New ArrayList
    > Outside the Private Sub Page_Load(ByVal sender As System.Object, ByVal e

    As

    Is it *outside* or *inside*? If it is outside, setting a accessible level of
    protected is most appropriate (eg: Protected ItemTypes As New ArrayList).

    > System.EventArgs) Handles MyBase.Load and have a function that refs it:-
    > Function SetIndex(ByVal TheItem As String)
    > Dim i As Integer
    > For i = 0 To ItemTypes.Count - 1
    > If TheItem = ItemTypes(i) Then
    > Return i
    > End If
    > Next
    > End Function


    This code will not compile - it will give "Not all code paths return value"
    compilation error. Also, note that there is an instance method on the
    ArrayList class that does what your function does - it is called IndexOf.
    See:

    http://msdn.microsoft.com/library/e...stemCollectionsArrayListClassIndexOfTopic.asp

    So your function will be reduced to:

    Function SetIndex(ByVal TheItem As String)
    Return ItemTypes.IndexOf(TheItem)
    End Function

    Another thing - more appropriate name is GetIndex instead of SetIndex

    > WHat could cause THIS ERROR?
    > Any ideas!



    Hope this helps
    Martin
    Martin Dechev, Oct 5, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack Wright
    Replies:
    3
    Views:
    1,624
    Chris Jackson
    Jan 5, 2004
  2. Murphy
    Replies:
    6
    Views:
    4,766
    Murphy
    Apr 20, 2004
  3. Richard
    Replies:
    1
    Views:
    1,787
    Steven Cheng[MSFT]
    Jul 27, 2004
  4. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    Error(ItemTypes As ArrayList) Name 'ItemTypes' is not declared

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    473
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Oct 4, 2004
  5. Murphy
    Replies:
    2
    Views:
    250
    Murphy
    Apr 26, 2004
Loading...

Share This Page