Solved

Im getting an error in my VB.NET code

Posted on 2004-10-12
9
140 Views
Last Modified: 2010-04-23
Why does the following cause an error?

Dim NoSelectedText as String = "blankanswer"
Dim NoSelectedValue as String = "Incorrect"

If RadQ1.SelectedItem.Text = "" or RadQ1.SelectedItem.Value = "" Then
RadQ1.SelectedItem.Text =NoSelectedText
RadQ1.SelectedItem.Value =NoSelectedValue
End If
0
Comment
Question by:pgilfeather
[X]
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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 12288075
what is radQ1 ??
0
 

Author Comment

by:pgilfeather
ID: 12288107
radQ1 is th id of a radiobuttonlist
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12288240
It's necessary that "blankanswer" or "Incorrect" is present in RadQ1 & with correct cAsE to set them up.

You'll receive this error if you haven't added "blankanswer" in RadQ1. After adding it to RadQ1 you can just set it up like following:

-------------------------------------------------------------------------------------------
Dim NoSelectedText as String = "blankanswer"
Dim NoSelectedValue as String = "Incorrect"

If RadQ1.SelectedItem.Text = "" or RadQ1.SelectedItem.Value = "" Then
RadQ1.SelectedItem.Value =NoSelectedValue  'You dont need to setup both
End If
-------------------------------------------------------------------------------------------

-tushar
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pgilfeather
ID: 12288424
tusharashah,

The error I am getting is as follows

System.NullReferenceException: Object reference not set to an instance of an object.

Its driving me nuts!!!!
0
 
LVL 7

Expert Comment

by:natloz
ID: 12288540
What line are you getting the error on?
0
 
LVL 13

Expert Comment

by:Corey2
ID: 12288980
Dim NoSelectedText as String = "blankanswer"
Dim NoSelectedValue as String = "Incorrect"
if not RadQ1.SelectedItem is nothing then
  If RadQ1.SelectedItem.Text = "" or RadQ1.SelectedItem.Value = "" Then
    RadQ1.SelectedItem.Text =NoSelectedText
    RadQ1.SelectedItem.Value =NoSelectedValue
  End If
else
  msgbox "Nothing is selected!"
end if
0
 
LVL 13

Accepted Solution

by:
Corey2 earned 500 total points
ID: 12289177
I believe your problem may be that you have moved on to RadQ2 and nothing in RadQ1 is selected any more.  You will have to check the values of each radio button.

dim ThisButton as object
Dim SelectedButton as radiobutton

For each Thisbutton in RadQ1.Items
     if thisbutton.value = True then
        selectedbutton = thisbutton
        exit for
    end if
next


dim NoSelectedText as String = "blankanswer"
Dim NoSelectedValue as String = "Incorrect"

if not selectedbutton  is nothing then
  If selectedbutton.Text = "" or selectedbutton.value = "" Then
    selectedbutton.Text = NoSelectedText
    selectedbutton.Value = NoSelectedValue
  End If
else
  msgbox "Nothing has been selected!"
end if
0
 
LVL 13

Expert Comment

by:Corey2
ID: 12289199
I meant to have this to check if the button has been checked.

For each Thisbutton in RadQ1.Items
     if thisbutton.checked = True then
        selectedbutton = thisbutton
        exit for
    end if
next
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12289223
Have you added anyitem? with name "blankanswer" and value "Incorrect" ?
I believe you haven't and That's why you are getting this error. You need to add an Item with TextField "blankanswer" and Value "Incorrect" first.

You can either add this item in design view or programatically like following:


--> RadQ1.Items.Add( new ListItem("blankanswer","Incorrect") )    'Make sure you add this Item before you refere it!

-tushar


0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…

734 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