By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

Random image generation

P: n/a
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.RaisePostBackEven t(String eventArgument)
+78
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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
Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You have not defined the size of the array, therefore imagegen(0) does not
exist.

"Jim in Arizona" <ti*******@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
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.RaisePostBackEven t(String
eventArgument) +78

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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

Nov 23 '05 #2

P: n/a
Yep. That was it exactly!

Thanks!

Jim

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
You have not defined the size of the array, therefore imagegen(0) does not
exist.

"Jim in Arizona" <ti*******@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
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.RaisePostBackEven t(String
eventArgument) +78

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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


Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.