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

G

Guest

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!
 
M

Martin Dechev

Hi,

See inline:

Patrick.O.Ige said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top