Solved

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

Posted on 2012-04-05
2
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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