473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

index was outside the bounds of the array

1
An error shows rarely iindex was outside the bounds of the array in line number 160





Line number 160 starts below.
Expand|Select|Wrap|Line Numbers
  1.          string s = "";
  2.                 if (imgname[pageno - 1, 0] != null)
  3.                 {
  4.                     ImageButton1.Visible = true;
  5.                     TextBox1.Visible = true;
  6.                     ImageButton1.ImageUrl = image_url + imgname[pageno - 1, 0];
  7.                     ImageButton1.AlternateText = imgname[pageno - 1, 0];
  8.                     s = "<p><a href=\"http://www.status99.com/home.aspx\" target=\"_blank\"><img src=\" http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 0] + "\" alt=\"\" /> </a><br><a href=\"www.status99.com\"><br /><img src=\"http://www.status99.com/images/arrow.gif\" alt=\"\" /><br />status99.com , V4orkut.info(" + setcategory(type) + ") </a></p>";
  9.                     TextBox1.Text = s;
  10.                     //Literal1.Text = "<a name=\"fb_share\" type=\"box_count\" share_url=\"http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 0] + "\"></a>" +
  11.                     //                       "<script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>";
  12.                     ImgButtonUFB_1.Visible = true;
  13.                     divMessaegUFB_1.Visible = true;
  14.  
  15.          lblDesc1.Text = GetImgDesc(imgname[pageno - 1, 0]); 
  16.  
  17.                 }
  18.                 if (imgname[pageno - 1, 1] != null)
  19.                 {
  20.                     ImageButton2.Visible = true;
  21.                     TextBox2.Visible = true;
  22.                     ImageButton2.ImageUrl = image_url + imgname[pageno - 1, 1];
  23.                     ImageButton2.AlternateText = imgname[pageno - 1, 1];
  24.                     s = "<p><a href=\"http://www.status99.com/home.aspx\" target=\"_blank\"><img src=\" http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 1] + "\" alt=\"\" /> </a><br><a href=\"www.status99.com\"><br /><img src=\"http://www.status99.com/images/arrow.gif\" alt=\"\" /><br />status99.com  V4orkut.info(" + setcategory(type) + ") </a></p>";
  25.                     TextBox2.Text = s;
  26.                     //Literal2.Text = "<a name=\"fb_share\" type=\"box_count\" share_url=\"http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 1] + "\"></a>" +
  27.                     //                       "<script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>";
  28.                     ImgButtonUFB_2.Visible = true;
  29.                     divMessaegUFB_2.Visible = true;
  30.  
  31.           lblDesc2.Text = GetImgDesc(imgname[pageno - 1, 1]); 
  32.  
  33.                 }
  34.                 if (imgname[pageno - 1, 2] != null)
  35.                 {
  36.                     ImageButton3.Visible = true;
  37.                     TextBox3.Visible = true;
  38.                     ImageButton3.ImageUrl = image_url + imgname[pageno - 1, 2];
  39.                     ImageButton3.AlternateText = imgname[pageno - 1, 2];
  40.                     s = "<p><a href=\"http://www.status99.com/home.aspx\" target=\"_blank\"><img src=\" http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 2] + "\" alt=\"\" /> </a><br><a href=\"www.status99.com\"><br /><img src=\"http://www.status99.com/images/arrow.gif\" alt=\"\" /><br />status99.com V4orkut.info (" + setcategory(type) + ") </a></p>";
  41.                     TextBox3.Text = s;
  42.                     //Literal3.Text = "<a name=\"fb_share\" type=\"box_count\" share_url=\"http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 2] + "\"></a>" +
  43.                     //                       "<script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>";
  44.                     ImgButtonUFB_3.Visible = true;
  45.                     divMessaegUFB_3.Visible = true;
  46.  
  47.         lblDesc3.Text = GetImgDesc(imgname[pageno - 1, 2]); 
  48.  
  49.                 }
  50.                 if (imgname[pageno - 1, 3] != null)
  51.                 {
  52.                     ImageButton4.Visible = true;
  53.                     TextBox4.Visible = true;
  54.                     ImageButton4.ImageUrl = image_url + imgname[pageno - 1, 3];
  55.                     ImageButton4.AlternateText = imgname[pageno - 1, 3];
  56.                     s = "<p><a href=\"http://www.status99.com/home.aspx\" target=\"_blank\"><img src=\" http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 3] + "\" alt=\"\" /> </a><br><a href=\"www.status99.com\"><br /><img src=\"http://www.status99.com/images/arrow.gif\" alt=\"\" /><br />status99.com V4orkut.info (" + setcategory(type) + ") </a></p>";
  57.                     TextBox4.Text = s;
  58.                     //Literal4.Text = "<a name=\"fb_share\" type=\"box_count\" share_url=\"http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 3] + "\"></a>" +
  59.                     //                       "<script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>";
  60.  
  61.                     ImgButtonUFB_4.Visible = true;
  62.                     divMessaegUFB_4.Visible = true;
  63.          lblDesc4.Text = GetImgDesc(imgname[pageno - 1, 3]); 
  64.                 }
  65.                 if (imgname[pageno - 1, 4] != null)
  66.                 {
  67.                     ImageButton5.Visible = true;
  68.                     TextBox5.Visible = true;
  69.                     ImageButton5.ImageUrl = image_url + imgname[pageno - 1, 4];
  70.                     ImageButton5.AlternateText = imgname[pageno - 1, 4];
  71.                     s = "<p><a href=\"http://www.status99.com/home.aspx\" target=\"_blank\"><img src=\" http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 4] + "\" alt=\"\" /> </a><br><a href=\"www.status99.com\"><br /><img src=\"http://www.status99.com/images/arrow.gif\" alt=\"\" /><br />status99.com (" + setcategory(type) + ") </a></p>";
  72.                     TextBox5.Text = s;
  73.                     //Literal5.Text = "<a name=\"fb_share\" type=\"box_count\" share_url=\"http://status99.com/main/greetings/" + type + "/" + imgname[pageno - 1, 4] + "\"></a>" +
  74.                     //                       "<script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>";
  75.                     ImgButtonUFB_5.Visible = true;
  76.                     divMessaegUFB_5.Visible = true;
  77.  
  78.          lblDesc5.Text = GetImgDesc(imgname[pageno - 1, 4]); 
  79.                 }
  80.  
  81.  
  82.                 pages = imgname.Length / 5;
  83.                 int rem = pageno % 8;
  84.                 int x = 1;
  85.                 if (pageno >= 1 && pageno <= 8)
  86.                 {
  87.                     x = 1;
  88.                 }
  89.                 else
  90.                 {
  91.                     if (rem == 0)
  92.                     {
  93.                         x = (pageno - 8) + 1;
  94.                     }
  95.                     else
  96.                     {
  97.                         x = pageno - (rem - 1);
  98.                     }
  99.                 }
Feb 9 '12 #1
1 2525
A simple yet commonly overlooked solution to this is your pageno variable.

This line:
Expand|Select|Wrap|Line Numbers
  1. if (imgname[pageno - 1, 0] != null)
will throw the exception when pageno is 0 or less.

This is because the exception is thrown even before the program checks to see if the reference exists or not.

To rectify the issue, change this line to:
Expand|Select|Wrap|Line Numbers
  1. if (pageno > 0 && imgname[pageno - 1, 0] != null)
this will be false when pageno is 0 or less and when the imgname reference is null.

if pageno is not >0, it won't check the imgname reference and return false.


P.S. Before you make posts in the future, please wrap your code in CODE tags, its a lot neater and easier to find problems.
Feb 9 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joe | last post by:
This is a weird problem. when doing trying to add a tabpage to a tabcontrol I get an error: Index was outside the bounds of the array. Now this only happens when I call a function from within...
3
by: ORC | last post by:
I have a large array where the first index must be removed, but how is the best way to do that when the application must be optimized to speed? Thanks Ole
2
by: B-Dog | last post by:
Any idea why when I try to fill my dataset using xContacts.Fill(xds.Contacts) I get the error: : Index was outside the bounds of the array. I've tried rebuilding my dataadapters and dataset...
1
by: Allen Maki | last post by:
Why can I get the index of the item of the array when I use string*, but can not get the index of the array when I use any other type (such as Int32)? This code will compile perfectly, but if I...
6
by: routeslip | last post by:
I'm refering to an entry in an array by it's string key, as in foo. Is there a way to get the numeric index of that array without iterating through the entire array? What I need to do is find...
3
by: writebrent | last post by:
I wrote a little interface for users to post data to a website. On their local machines, it produces CSV from an Excel spreadsheet, then posts it to the site. In some cases, the CSV will contain...
3
by: Erwin Moller | last post by:
Hi, Consider the following code: ------------------------- function giveArr(){ return array("one","two","three"); } echo giveArr();
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
1
foolios
by: foolios | last post by:
private void CreateMaze(int h, int w) { int r = h * w; Room rooms = new Room; Random rm = new Random(); int newrm = rm.Next(0, r); ...
7
by: bouy78 | last post by:
Quick Question Seems to be an easy task, but apparently I'm not very bright. I have an array of checkboxes, created at runtime and inserted in a panel. Upon creation, they're each attached to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.