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
Solved

Dictionnary.add()

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

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.

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

Suggested Solutions

Title # Comments Views Activity
Import a txt file into a DataGridView and TextBox 20 52
Database Connections Not being returned to Connection Pool 7 34
vb.net class 3 21
VB.NET 2008 Winforms Signing 13 31
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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