Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Im getting an error in my VB.NET code

Posted on 2004-10-12
9
Medium Priority
?
143 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
Independent Software Vendors: 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:Corey Scheich
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:
Corey Scheich earned 1500 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:Corey Scheich
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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