Posted on 2006-07-17
Medium Priority
Last Modified: 2010-04-23
having error NullReferenceExecption on lign: myLabels.Add(ctrl.name, ctrl)

Imports System.Collections.Generic

 Dim myButtons As Dictionary(Of String, Button)
 Dim myLabels As Dictionary(Of String, Label)
Private Sub frmRoom_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        For Each ctrl As Control In Me.Controls
            If TypeOf (ctrl) Is Button Then
                myButtons.Add(ctrl.name, ctrl)
            ElseIf TypeOf (ctrl) Is Label Then
                myLabels.Add(ctrl.name, ctrl)
            End If
End Sub

any ideas folks !?!!?
Question by:PhilippeRenaud
LVL 10

Accepted Solution

bchoor earned 2000 total points
ID: 17125017
2 alternatives

Private Sub....

if myButtons is Nothing then myButtons = New Dictionary(Of String, Button)
if myLabels is nothing then myLabels = New Dictionary(Of String, Label)

For each...

End Sub

Dim myButtons As New Dictionary(Of String, Button)
Dim myLabels As new Dictionary(Of String, Label)


Author Comment

ID: 17125040
duh, you're right. needed the  "new' ....

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
Suggested Courses

600 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