473,799 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

index was outside the bounds of the array

1 New Member
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 2537
Samuel Jones
48 New Member
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
2340
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 a callback for an Async webmethod call. My guess is that it has something to do with the threads not being in sync yet.
3
2402
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
1366
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 and still get the error, can preview it fine. Thanks
1
1506
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 replace String* with Int32, the code would not compile? The code using String* type: #include "stdafx.h"
6
2242
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 the "next" or "previous" entry in the array, but the keys are strings, instead of numerical indeces. thanks for your help.
3
3163
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 ampersands. For example, abc,American & British Company,1,4.34,5 ded,Dog Eat Dog,2,6.3,5.766 The code on the site is pretty standard: it loops through an array of lines from the CSV split on line ends, and then loops through another
3
1235
by: Erwin Moller | last post by:
Hi, Consider the following code: ------------------------- function giveArr(){ return array("one","two","three"); } echo giveArr();
6
2727
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 action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type=\"submit\"...
1
1320
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); int nrmcntr = newrm; do { rooms.rWall = "|";
7
1923
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 the same CheckChanged event. Within this event, how do I know the index of the checkbox that triggered it? Thanks in advance.
0
10485
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.