Random image generation

J

Jim in Arizona

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
 
P

Peter Rilling

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

Jim in Arizona said:
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
 
J

Jim in Arizona

Yep. That was it exactly!

Thanks!

Jim

Peter Rilling said:
You have not defined the size of the array, therefore imagegen(0) does not
exist.

Jim in Arizona said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top