4 Replies - 2965 Views - Last Post: 07 March 2011 - 04:00 PM Rate Topic: -----

#1 STP_Captain_Slow  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 75
  • Joined: 08-October 10

VB.NET - Null Reference Exception was unhandled

Posted 07 March 2011 - 07:25 AM

Hi

I have the following code, which is meant to loop through a list of CheckBoxes and if checked if gets the text contained in the linked textbox through the tag of the Checkbox, i have used it before and it worked fine but this time i am getting the following error:

Null Reference Exception was unhandled


Dim DisCheckBox As CheckBox() = {chk0_6, chk6_12, chk12_18, chk18_24, chk2_3, chk3_4, chk4_5, chkXSB, chkSB, chkMB, chkLB, chkXLB, chkS, chkM, chkL, chkXL, chkXXL, chkXXXL, chkXXXXL, chkW8, chkW10, chkW12, chkW14, chkW16, chkW18, chkW20}

For Each Chk In DisCheckBox

                If Chk.CheckState = CheckState.Checked Then

                    txtTest.Text = CType(pnlChk.Controls(Chk.Tag.ToString()), TextBox).Text()

                End If

            Next



Any help would be very grateful.

This post has been edited by STP_Captain_Slow: 07 March 2011 - 07:47 AM


Is This A Good Question/Topic? 0
  • +

Replies To: VB.NET - Null Reference Exception was unhandled

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6106
  • View blog
  • Posts: 23,653
  • Joined: 23-August 08

Re: VB.NET - Null Reference Exception was unhandled

Posted 07 March 2011 - 07:43 AM

Please do NOT use a title like "VB.NET" in the VB.NET forum. We KNOW it's a VB.NET topic or you wouldn't have posted it in the VB.NET forum!!! Give your topic a descriptive title, like that to which I've changed yours.
Was This Post Helpful? 0
  • +
  • -

#3 STP_Captain_Slow  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 75
  • Joined: 08-October 10

Re: VB.NET - Null Reference Exception was unhandled

Posted 07 March 2011 - 07:48 AM

View PostJackOfAllTrades, on 07 March 2011 - 07:43 AM, said:

Please do NOT use a title like "VB.NET" in the VB.NET forum. We KNOW it's a VB.NET topic or you wouldn't have posted it in the VB.NET forum!!! Give your topic a descriptive title, like that to which I've changed yours.



Yea thanks, it was a mistake as i was meant to go back and fill it in
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,498
  • Joined: 29-May 08

Re: VB.NET - Null Reference Exception was unhandled

Posted 07 March 2011 - 03:24 PM

Could you explain what you're trying to do? What is the function of the code?
Was This Post Helpful? 0
  • +
  • -

#5 STP_Captain_Slow  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 75
  • Joined: 08-October 10

Re: VB.NET - Null Reference Exception was unhandled

Posted 07 March 2011 - 04:00 PM

It will loop through a series of Checkboxes and if the checkbox is checked it will take the value in the related textbox and populate a datatable. i am just using the test text box to see if i can get a value. I have used this before and i can't understand why it won't work this time. The link between the checkbox and the textbox is through the tag of the checkbox.

E.G.


Checkbox Name: chkS
Checkbox Tag: txtS

above code should take the Tag and turn it into a textbox variable - txtS.Text

and that is the value that will be used.

I know the tag is correct and i know the textbox is not null as every textbox has a value.

The text under the error is:

Object reference not set to an instance of an object.

This post has been edited by STP_Captain_Slow: 07 March 2011 - 04:24 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1