Hello everybody,


I'm creating a control array which I need to make on certain moment visible or not.

Right now the only controls in my ctl array are labels. If I want to make them visible, I want to use in my ShowInvoice sub a loop to loop through my control array.
Everything works fine ... only if I use
VB Code:
  1. typeof sInvoice(i) is label then
  2. sInvoice(i).visible=true
  3. end if

If I just use sInvoice(i).visible = true (without the typeof condition) then I receive Object reference not set to an instance of an object
I don't want to change my showinvoice routine each time when there's a new kind of control in my array !

I really don't see why this is happening !

Hope someone can help me out !

This is my code (this doesn't work => but I want this one to work)

VB Code:
  1. Private Function InvoiceArray()
  2.  
  3.         Dim sInvoice(20) As Control
  4.  
  5.         sInvoice(1) = lblInvoiceTo
  6.         sInvoice(2) = lblInvoiceName
  7.         sInvoice(3) = lblInvoiceAddress
  8.         sInvoice(4) = lblInvoiceNr
  9.         sInvoice(5) = lblInvoiceZip
  10.         sInvoice(6) = lblInvoicePlace
  11.  
  12.         Return sInvoice
  13.  
  14.     End Function
  15.  
  16. Private Sub ShowInvoice()
  17.         Dim sInvoice() As Control
  18.         Dim i As Integer
  19.         sInvoice = InvoiceArray()
  20.  
  21.         Dim ctl As Control
  22.         For i = 0 To UBound(sInvoice)
  23.             sInvoice(i).Visible = True
  24.         Next


This doesn't work

VB Code:
  1. For i = 0 To UBound(sInvoice)
  2.             sInvoice(i).Visible = True
  3.             If TypeOf sInvoice(i) Is Label Then
  4.                 sInvoice(i).Visible = True
  5.                 Response.Write(sInvoice(i).GetType.ToString)
  6.             End If
  7.         Next