Solved

Error: Object reference not set to an instance of an object.

Posted on 2012-04-05
2
179 Views
Last Modified: 2012-06-21
I have the following loop:

 
If fvShip.CurrentMode = FormViewMode.ReadOnly Then
            Dim bLinks() As LinkButton = {bLink, bLink1, bLink2, bLink3, bLink4}
            Dim lblFileLengths() As Label = {lblFileLength, lblFileLength1, lblFileLength2, lblFileLength3, lblFileLength4}
            For i As Integer = 0 To lblFileLengths.Length - 1
                If lblFileLengths(i).Text = "0" Then
                    bLinks(i).Visible = False
                End If
            Next
        End If

Open in new window


and get the  Error: Object reference not set to an instance of an object at
  --If lblFileLengths(i).Text = "0" Then

can someone assist?
0
Comment
Question by:JessyRobinson1234
2 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 500 total points
ID: 37812369
Your code appears correct.  I wrote an example and was able to step through and confirm it working correctly.  Something is coming back as null in your labels it looks like.  Are you sure the labels have the correct properties set?  

Dim lbl1 As New Label()
        lbl1.Text = "0"
        Dim lbl2 As New Label()
        lbl2.Text = "1"
        Dim lbl3 As New Label()
        lbl3.Text = "2"

        Dim testFileLengths() As Label = {lbl1, lbl2, lbl3}
        For i As Integer = 0 To testFileLengths.Length - 1
            If testFileLengths(i).Text = "0" Then

                Dim s As String = "Im here"

            End If
        Next

Open in new window

0
 
LVL 21

Expert Comment

by:mastoo
ID: 37813248
Can you look at the values in the debugger when the error occurs?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 28
Maintain selection of the datagrdview 8 20
Code enhancement 5 13
Set form below another form 3 26
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now