Random image generation

Discussion in 'ASP .Net' started by Jim in Arizona, Nov 23, 2005.

  1. I was trying to create a random image generator. I'm using visual web dev
    express with 2.0 framework.

    On the web form page (mypage.aspx), I have an image control:

    <asp:Image ID="Image1" runat="server" />

    On the codebehind, (mypage.aspx.vb), I have this code when a button is
    clicked:

    Dim imagegen() As String
    Dim x As Short

    x = CShort(Rnd() * 15)

    imagegen(0) = "../images/ticketimages/atlascow.jpg"
    imagegen(1) = "../images/ticketimages/carpool.bmp"
    imagegen(2) = "../images/ticketimages/catsquirrel.jpg"
    imagegen(3) = "../images/ticketimages/creature.jpeg"
    imagegen(4) = "../images/ticketimages/fitnessescalator.bmp"
    imagegen(5) = "../images/ticketimages/frogcat.jpg"
    imagegen(6) = "../images/ticketimages/helicopter.jpg"
    imagegen(7) = "../images/ticketimages/highheelbike.bmp"
    imagegen(8) = "../images/ticketimages/kisspandas.jpg"
    imagegen(9) = "../images/ticketimages/libertylegs.jpg"
    imagegen(10) = "../images/ticketimages/portapotty.bmp"
    imagegen(11) = "../images/ticketimages/rabbitfingers.jpg"
    imagegen(12) = "../images/ticketimages/santaplane.bmp"
    imagegen(13) = "../images/ticketimages/sharkattack.jpg"
    imagegen(14) = "../images/ticketimages/swissarmyant.jpg"
    imagegen(15) = "../images/ticketimages/whaletail.jpg"

    Image1.ImageUrl = imagegen(x)

    When I tested the code, I got this error:

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.

    Source Error:


    Line 346: Dim x As Short
    Line 347: x = CShort(Rnd() * 15)
    Line 348: imagegen(0) = "../images/ticketimages/atlascow.jpg"
    Line 349: imagegen(1) = "../images/ticketimages/carpool.bmp"
    Line 350: imagegen(2) = "../images/ticketimages/catsquirrel.jpg"


    Source File: E:\hhsinternal\Tickets\problem.aspx.vb Line: 348

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an
    object.]
    problem.btnReportProblem_Click(Object sender, EventArgs e) in
    E:\hhsinternal\Tickets\problem.aspx.vb:348
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
    +78
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670

    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET
    Version:2.0.50215.44


    I'm a newbie with asp.net and vb.net. I've come a long ways but it seems
    i've got a very long ways to go before I've got a clear understanding of
    most of this stuff.

    Thanks for the help!

    Jim
     
    Jim in Arizona, Nov 23, 2005
    #1
    1. Advertising

  2. You have not defined the size of the array, therefore imagegen(0) does not
    exist.

    "Jim in Arizona" <> wrote in message
    news:...
    >I was trying to create a random image generator. I'm using visual web dev
    >express with 2.0 framework.
    >
    > On the web form page (mypage.aspx), I have an image control:
    >
    > <asp:Image ID="Image1" runat="server" />
    >
    > On the codebehind, (mypage.aspx.vb), I have this code when a button is
    > clicked:
    >
    > Dim imagegen() As String
    > Dim x As Short
    >
    > x = CShort(Rnd() * 15)
    >
    > imagegen(0) = "../images/ticketimages/atlascow.jpg"
    > imagegen(1) = "../images/ticketimages/carpool.bmp"
    > imagegen(2) = "../images/ticketimages/catsquirrel.jpg"
    > imagegen(3) = "../images/ticketimages/creature.jpeg"
    > imagegen(4) = "../images/ticketimages/fitnessescalator.bmp"
    > imagegen(5) = "../images/ticketimages/frogcat.jpg"
    > imagegen(6) = "../images/ticketimages/helicopter.jpg"
    > imagegen(7) = "../images/ticketimages/highheelbike.bmp"
    > imagegen(8) = "../images/ticketimages/kisspandas.jpg"
    > imagegen(9) = "../images/ticketimages/libertylegs.jpg"
    > imagegen(10) = "../images/ticketimages/portapotty.bmp"
    > imagegen(11) = "../images/ticketimages/rabbitfingers.jpg"
    > imagegen(12) = "../images/ticketimages/santaplane.bmp"
    > imagegen(13) = "../images/ticketimages/sharkattack.jpg"
    > imagegen(14) = "../images/ticketimages/swissarmyant.jpg"
    > imagegen(15) = "../images/ticketimages/whaletail.jpg"
    >
    > Image1.ImageUrl = imagegen(x)
    >
    > When I tested the code, I got this error:
    >
    > Server Error in '/' Application.
    > --------------------------------------------------------------------------------
    >
    > Object reference not set to an instance of an object.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > Source Error:
    >
    >
    > Line 346: Dim x As Short
    > Line 347: x = CShort(Rnd() * 15)
    > Line 348: imagegen(0) = "../images/ticketimages/atlascow.jpg"
    > Line 349: imagegen(1) = "../images/ticketimages/carpool.bmp"
    > Line 350: imagegen(2) = "../images/ticketimages/catsquirrel.jpg"
    >
    >
    > Source File: E:\hhsinternal\Tickets\problem.aspx.vb Line: 348
    >
    > Stack Trace:
    >
    > [NullReferenceException: Object reference not set to an instance of an
    > object.]
    > problem.btnReportProblem_Click(Object sender, EventArgs e) in
    > E:\hhsinternal\Tickets\problem.aspx.vb:348
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
    > System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    > eventArgument) +78
    >
    > System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    > eventArgument) +7
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument) +11
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    > System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670
    >
    > --------------------------------------------------------------------------------
    > Version Information: Microsoft .NET Framework Version:2.0.50215.44;
    > ASP.NET Version:2.0.50215.44
    >
    >
    > I'm a newbie with asp.net and vb.net. I've come a long ways but it seems
    > i've got a very long ways to go before I've got a clear understanding of
    > most of this stuff.
    >
    > Thanks for the help!
    >
    > Jim
    >
     
    Peter Rilling, Nov 23, 2005
    #2
    1. Advertising

  3. Yep. That was it exactly!

    Thanks!

    Jim

    "Peter Rilling" <> wrote in message
    news:...
    > You have not defined the size of the array, therefore imagegen(0) does not
    > exist.
    >
    > "Jim in Arizona" <> wrote in message
    > news:...
    >>I was trying to create a random image generator. I'm using visual web dev
    >>express with 2.0 framework.
    >>
    >> On the web form page (mypage.aspx), I have an image control:
    >>
    >> <asp:Image ID="Image1" runat="server" />
    >>
    >> On the codebehind, (mypage.aspx.vb), I have this code when a button is
    >> clicked:
    >>
    >> Dim imagegen() As String
    >> Dim x As Short
    >>
    >> x = CShort(Rnd() * 15)
    >>
    >> imagegen(0) = "../images/ticketimages/atlascow.jpg"
    >> imagegen(1) = "../images/ticketimages/carpool.bmp"
    >> imagegen(2) = "../images/ticketimages/catsquirrel.jpg"
    >> imagegen(3) = "../images/ticketimages/creature.jpeg"
    >> imagegen(4) = "../images/ticketimages/fitnessescalator.bmp"
    >> imagegen(5) = "../images/ticketimages/frogcat.jpg"
    >> imagegen(6) = "../images/ticketimages/helicopter.jpg"
    >> imagegen(7) = "../images/ticketimages/highheelbike.bmp"
    >> imagegen(8) = "../images/ticketimages/kisspandas.jpg"
    >> imagegen(9) = "../images/ticketimages/libertylegs.jpg"
    >> imagegen(10) = "../images/ticketimages/portapotty.bmp"
    >> imagegen(11) = "../images/ticketimages/rabbitfingers.jpg"
    >> imagegen(12) = "../images/ticketimages/santaplane.bmp"
    >> imagegen(13) = "../images/ticketimages/sharkattack.jpg"
    >> imagegen(14) = "../images/ticketimages/swissarmyant.jpg"
    >> imagegen(15) = "../images/ticketimages/whaletail.jpg"
    >>
    >> Image1.ImageUrl = imagegen(x)
    >>
    >> When I tested the code, I got this error:
    >>
    >> Server Error in '/' Application.
    >> --------------------------------------------------------------------------------
    >>
    >> Object reference not set to an instance of an object.
    >> Description: An unhandled exception occurred during the execution of the
    >> current web request. Please review the stack trace for more information
    >> about the error and where it originated in the code.
    >>
    >> Exception Details: System.NullReferenceException: Object reference not
    >> set to an instance of an object.
    >>
    >> Source Error:
    >>
    >>
    >> Line 346: Dim x As Short
    >> Line 347: x = CShort(Rnd() * 15)
    >> Line 348: imagegen(0) = "../images/ticketimages/atlascow.jpg"
    >> Line 349: imagegen(1) = "../images/ticketimages/carpool.bmp"
    >> Line 350: imagegen(2) = "../images/ticketimages/catsquirrel.jpg"
    >>
    >>
    >> Source File: E:\hhsinternal\Tickets\problem.aspx.vb Line: 348
    >>
    >> Stack Trace:
    >>
    >> [NullReferenceException: Object reference not set to an instance of an
    >> object.]
    >> problem.btnReportProblem_Click(Object sender, EventArgs e) in
    >> E:\hhsinternal\Tickets\problem.aspx.vb:348
    >> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
    >> System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    >> eventArgument) +78
    >>
    >> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    >> eventArgument) +7
    >> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    >> sourceControl, String eventArgument) +11
    >> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    >> System.Web.UI.Page.ProcessRequestMain(Boolean
    >> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    >> +5670
    >>
    >> --------------------------------------------------------------------------------
    >> Version Information: Microsoft .NET Framework Version:2.0.50215.44;
    >> ASP.NET Version:2.0.50215.44
    >>
    >>
    >> I'm a newbie with asp.net and vb.net. I've come a long ways but it seems
    >> i've got a very long ways to go before I've got a clear understanding of
    >> most of this stuff.
    >>
    >> Thanks for the help!
    >>
    >> Jim
    >>

    >
    >
     
    Jim in Arizona, Nov 23, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    579
  2. globalrev
    Replies:
    4
    Views:
    768
    Gabriel Genellina
    Apr 20, 2008
  3. Waverider
    Replies:
    1
    Views:
    196
    JuanDG
    Sep 21, 2004
  4. John W. Long

    HTML Generation (Next Generation CGI)

    John W. Long, Nov 22, 2003, in forum: Ruby
    Replies:
    4
    Views:
    340
    John W. Long
    Nov 24, 2003
  5. VK
    Replies:
    15
    Views:
    1,174
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page