Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Must be something obvious...

Status
Not open for further replies.

combs

Programmer
Apr 18, 2002
78
US
I have a snippet of code that is not working... It was outside of a for loop and worked when I addressed the labels and textboxes individually. Now (inside the for loop) it can't seem to "find" the labels or textboxes....

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

Code:
For i = New Int16 To m_Dataset.Tables("tblCorners").Rows.Count - 1
            [COLOR=green]''LABEL ATTRIBUTES[/color]
            Me.Controls("lblCorner" & i).Enabled = True
            Me.Controls("lblCorner" & i).Visible = True
            Me.Controls("lblCorner" & i).Text = m_Dataset.Tables("tblCorners").Rows(i)(0).ToString
            [COLOR=green]'TEXTBOX ATTRIBUTES[/color]
            Me.Controls("txtCorner" & i).Enabled = True
            Me.Controls("txtCorner" & i).Visible = True
            Me.Controls("txtCorner" & i).Text = FormatCurrency(m_Dataset.Tables("CornerNum" & i).Rows(0)(0), 2, TriState.False, TriState.False, TriState.True)
            dblTemp += Me.Controls("txtCorner" & i).Text
        Next

Any help diagnosing this would be greatly appreciated!
 
I don't think this will help, but change this line

Code:
For i = New Int16 To m_Dataset.Tables("tblCorners").Rows.Count - 1

to

Code:
For i As Integer = 0 To  m_Dataset.Tables("tblCorners").Rows.Count - 1

Honestly, I think you may have more rows in your DataTable than you have groups of controls. Do any of the iterations work? Or is it erring on the first iteration?

 
Thanks RiverGuy - it's erring on the first iteration -- 0

I have the labels named lblCorner0, lblCorner1 ....to 7
Same with the textboxes.

The can be successfully addressed by using this code:
Me.lblCorner0.Visible = True

I changed the code as you suggested and still no joy.


 
If the controls are in another control, such as a panel, you can access them like the following:

Code:
Panel1.Controls("lblCorner" & i.ToString()).Text = "Some Text"

Also, if you've created these controls through code and have not set the .Name property, you will need to do so.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top