Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:00:10+00:00 2026-06-11T21:00:10+00:00

The following gives me a nullreference error. How can i accomplish this simple task

  • 0

The following gives me a nullreference error. How can i accomplish this simple task while avoiding the error?

thanks!

Edit: L1,L2,etc are labels in my form.

Dim labelArray(,) As Label = {{L1, L2, L3, L4}, {L5, L6, L7, L8}, {L9, L10, L11, L12}, {L13, L14, L15, L16}}


private sub button_click(stuff that goes in here)
labelArray(zeroPoint.X, zeroPoint.Y).BackColor = Color.LimeGreen
end sub

EDIT: I got it to work by doing the following inside the form load method..

labelArray(0, 0) = Me.L1
    labelArray(0, 1) = Me.L2
    labelArray(0, 2) = Me.L3
    labelArray(0, 3) = Me.L4

    labelArray(1, 0) = Me.L5
    labelArray(1, 1) = Me.L6
    labelArray(1, 2) = Me.L7
    labelArray(1, 3) = Me.L8

    labelArray(2, 0) = Me.L9
    labelArray(2, 1) = Me.L10
    labelArray(2, 2) = Me.L11
    labelArray(2, 3) = Me.L12

    labelArray(3, 0) = Me.L13
    labelArray(3, 1) = Me.L14
    labelArray(3, 2) = Me.L15
    labelArray(3, 3) = Me.L16
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:00:12+00:00Added an answer on June 11, 2026 at 9:00 pm

    Your label array initializer runs before the InitializeComponent() method, where all your labels are instantiated. You are effectively adding a bunch of null references to the array.

    Leave the array declaration where it is, but move the assignment code to the end of the form’s constructor, and I think that will fix the problem.

    Beyond that, you’ll need to check the zeropoint.X and zeropoint.Y result in valid indexes. Remember that, by default, vb.net indexes work a little different than either C# or VB6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following C++ code gives an error while compiling: #include<iostream> using namespace std; class
The Following gives me a 407 error, Can anyone see why or where I'm
The following gives me the error Uncaught SyntaxError: Unexpected identifier : $('span.xtro').html(''); $('span.xtro').html('<input type='button'
The following code gives digits whose name is shorter than their value. I can't
The following code gives a NullReferenceException since XPathSelectElement can't navigate through the XPath expression
Any ideas why does the entity framework in LINQ gives following strange error: Unable
The following gives me an error message: public static List<Comparable<?>> merge(Set<List<Comparable<?>>> lists) { List<Comparable<?>>
The following gives an error drop function testing(); CREATE FUNCTION testing() RETURNS text AS
The following gives an Internal Compiler Error on MSVC++ 10 Sp1. And on gcc:
The following gives me an error of The server tag is not well formed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.