Solved

Dictionnary.add()

Posted on 2006-07-17
2
171 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Publish 13 46
Asp/Net Validation date Issue 9 38
Check if number is currency 15 29
Setting runtime form location 4 19
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

17 Experts available now in Live!

Get 1:1 Help Now