Re: Object Reference Error
From: One Handed Man \( OHM - Terry Burns \) ("One)
Date: 07/20/04
- Next message: SStory: "Re: Cannot run VB.net web application from debug menu (F5)"
- Previous message: Remulac: "Re: Object Reference Error"
- In reply to: Remulac: "Re: Object Reference Error"
- Next in thread: anonymous_at_discussions.microsoft.com: "Re: Object Reference Error"
- Reply: anonymous_at_discussions.microsoft.com: "Re: Object Reference Error"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 20 Jul 2004 20:09:57 +0100
sValue is not declared
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
Time flies when you don't know what you're doing
"Remulac" <anonymous@discussions.microsoft.com> wrote in message
news:0c8201c46e8b$84518120$a301280a@phx.gbl...
>
> Oops! My bad...
>
>
> Private Sub Button1_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> Button1.Click
> Try
> Response.Write(Session("AnimalTypeID"))
> sValue = ListBox1.Items
> (ListBox1.SelectedIndex).Value
> Response.Write(sValue)
> Catch ex As Exception
> Response.Write(ex.Message)
> End Try
> 'Server.Transfer("EditAnimalTypes.aspx")
> End Sub
>
>
> I'm getting the following error:
>
> "Index was out of range. Must be non-negative and less
> than the size of the collection. Parameter name: index "
>
> When I take out all references to the ADO.NET objects and
> populate the listbox manually, I don't get the error any
> more.
>
> Thanks for your help.
>
>
> >-----Original Message-----
> >Thanks, but you did not include the SelectedIndexChanged
> event handler which
> >is where you code is failing
> >
> >--
> >
> >OHM ( Terry Burns )
> > . . . One-Handed-Man . . .
> >
> >Time flies when you don't know what you're doing
> >
> >"Remulac" <anonymous@discussions.microsoft.com> wrote in
> message
> >news:0c0b01c46e86$88a479d0$a301280a@phx.gbl...
> >> Here's the code:
> >>
> >>
> >>
> >> 'This call is required by the Web Form Designer.
> >> <System.Diagnostics.DebuggerStepThrough()> Private
> Sub
> >> InitializeComponent()
> >>
> >> End Sub
> >> Protected WithEvents ListBox1 As
> >> System.Web.UI.WebControls.ListBox
> >> Protected WithEvents Button1 As
> >> System.Web.UI.WebControls.Button
> >>
> >> 'NOTE: The following placeholder declaration is
> >> required by the Web Form Designer.
> >> 'Do not delete or move it.
> >> Private designerPlaceholderDeclaration As
> System.Object
> >>
> >> Private Sub Page_Init(ByVal sender As System.Object,
> >> ByVal e As System.EventArgs) Handles MyBase.Init
> >> 'CODEGEN: This method call is required by the
> Web
> >> Form Designer
> >> 'Do not modify it using the code editor.
> >> InitializeComponent()
> >> End Sub
> >>
> >> #End Region
> >>
> >> Private Sub Page_Load(ByVal sender As System.Object,
> >> ByVal e As System.EventArgs) Handles MyBase.Load
> >> Dim cnVortex As New SqlClient.SqlConnection
> >> (System.Configuration.ConfigurationSettings.AppSettings
> >> ("ConnectionString"))
> >> Dim cdAnimalTypes As New SqlClient.SqlCommand
> >> ("usp_GetAnimalTypes", cnVortex)
> >> 'cdAnimalTypes.CommandType =
> >> CommandType.StoredProcedure
> >> cnVortex.Open()
> >> Dim daAnimalTypes As New
> SqlClient.SqlDataAdapter
> >> (cdAnimalTypes)
> >> Dim dsAnimalTypes As New DataSet
> >> daAnimalTypes.Fill(dsAnimalTypes, "AnimalTypes")
> >>
> >> ListBox1.DataSource = dsAnimalTypes
> >> ListBox1.DataTextField = "ANIMAL_TYPE"
> >> ListBox1.DataValueField = "ANIMAL_TYPE_ID"
> >> ListBox1.DataBind()
> >> End Sub
> >>
> >> Private Sub Button1_Click(ByVal sender As
> >> System.Object, ByVal e As System.EventArgs) Handles
> >> Button1.Click
> >> Try
> >> Response.Write(Session("AnimalTypeID"))
> >> Catch ex As Exception
> >> Response.Write(ex.Message)
> >> End Try
> >> 'Server.Transfer("EditAnimalTypes.aspx")
> >> End Sub
> >>
> >>
> >>
> >>
> >>
> >> >-----Original Message-----
> >> >Post your relevant code please.
> >> >
> >> >--
> >> >
> >> >OHM ( Terry Burns )
> >> > . . . One-Handed-Man . . .
> >> >
> >> >Time flies when you don't know what you're doing
> >> >
> >> >"Remulac" <anonymous@discussions.microsoft.com> wrote
> in
> >> message
> >> >news:08e401c46e6c$8c1905f0$a401280a@phx.gbl...
> >> >> Hello,
> >> >>
> >> >> I'm trying to get the value out of a dropdown list
> box
> >> and
> >> >> assign it to a variable. When I click on the list
> box,
> >> I
> >> >> invoke this line of code. I get the error, "Object
> >> >> reference not set to an instance of an object".
> >> >>
> >> >> The same list box is referenced successfully in the
> form
> >> >> load. Does anyone know what might cause this
> problem?
> >> >
> >> >
> >> >.
> >> >
> >
> >
> >.
> >
- Next message: SStory: "Re: Cannot run VB.net web application from debug menu (F5)"
- Previous message: Remulac: "Re: Object Reference Error"
- In reply to: Remulac: "Re: Object Reference Error"
- Next in thread: anonymous_at_discussions.microsoft.com: "Re: Object Reference Error"
- Reply: anonymous_at_discussions.microsoft.com: "Re: Object Reference Error"
- Messages sorted by: [ date ] [ thread ]