Solved

Dictionnary.add()

Posted on 2006-07-17
2
174 Views
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
        Next
End Sub


any ideas folks !?!!?
0
Comment
Question by:PhilippeRenaud
2 Comments
 
LVL 10

Accepted Solution

by:
bchoor earned 500 total points
ID: 17125017
2 alternatives

1.
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

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

HTH
~BC
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17125040
duh, you're right. needed the  "new' ....
 thanks.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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