Solved

Im getting an error in my VB.NET code

Posted on 2004-10-12
9
135 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
  • 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

12 Experts available now in Live!

Get 1:1 Help Now