Solved

Im getting an error in my VB.NET code

Posted on 2004-10-12
9
141 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
Industry Leaders: 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

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!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

726 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