Solved

Im getting an error in my VB.NET code

Posted on 2004-10-12
9
138 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Variable Event ? 3 36
VB.NET (2008) - Refactoring Question 2 24
Sql server, import complete table, using vb.net 9 43
Help with preventing selection from a combobox 11 34
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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