473,378 Members | 1,462 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,378 software developers and data experts.

Out of bounds error?

7
I've been developing a vb.net program for weeks with no problem. All of a sudden I'm getting an out of bounds error when I run it. I've tried running some of the earlier versions of the program which also used to run with no errors and find the same error pops up. Any ideas please anyone?
Sep 24 '07 #1
8 3720
hariharanmca
1,977 1GB
I've been developing a vb.net program for weeks with no ...............
Can you specify the exact error message?
(If it possible to post what you done with that before you getting this error?)
Sep 24 '07 #2
QVeen72
1,445 Expert 1GB
Hi,

Are you populating a ListBox/Combo/Grid with results of some SQL?
Maybe control does not have any items, and you are trying to access some items from that control, without checking if itemCount > 0
Can you post your code here?

Regards
Veena
Sep 24 '07 #3
hidara
7
************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at workprogsave.Folders.splitandsearch(String foldername) in C:\Documents and Settings\DO'Heidhin\Desktop\Newest 1.9\workprogsave\Folders.vb:line 168
at workprogsave.Folders.Findfolders() in C:\Documents and Settings\DO'Heidhin\Desktop\Newest 1.9\workprogsave\Folders.vb:line 121
at workprogsave.Main.Search_Click(Object sender, EventArgs e) in C:\Documents and Settings\DO'Heidhin\Desktop\Newest 1.9\workprogsave\Main.vb:line 22
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey( Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Mes sage& msg)
at System.Windows.Forms.Control.PreProcessControlMess ageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.Pre TranslateMessage(MSG& msg)


Above is the error I'm getting.I had my program working on 3 other computers and they all started giving the same error at the same time, the other computers only have the .exe version and don't have vb.net installed and I haven't changed any code! Could an xp update have caused this? Thank you for your replies, the have been really appreciated.
Sep 24 '07 #4
hidara
7
Here is the area of my code which is causing trouble. It searches our G: drive for a project folder ie. ("12345 - Royal Childrens Hospital") where the first set of no.s are the project no. If the search word finds matches in more than one project it populates a listbox with the results and allows the user to choose the correct folder. Thanks again.


Expand|Select|Wrap|Line Numbers
  1. Public Sub splitandsearch(ByVal foldername As String)
  2.  
  3.         ' takes each folder name and splits it into 
  4.         ' 1/ project no 
  5.         ' 2/ individual words
  6.         ' these are then matched with search word/s
  7.  
  8.         Dim OneCharacter As Char = foldername
  9.         Dim i As Integer
  10.         Dim aryTextFile(10) As String
  11.         Dim aryresult(50) As String 'if count over 50 create msgbox error
  12.         Dim projectdetails As String = System.IO.Path.GetFileName(foldername)
  13.         Dim projectname As String
  14.         Dim projectno As String = ""
  15.  
  16.  
  17.         projectdetails = projectdetails.Replace(" - ", " ") ' deletes symbols 
  18.  
  19.         aryTextFile = projectdetails.Split(" ") ' split at each space
  20.         For i = 0 To UBound(aryTextFile)
  21.  
  22.             aryTextFile(i) = aryTextFile(i).Trim(" ") ' delete extra spaces
  23.  
  24.             If IsNumeric(aryTextFile(i).Chars(0)) = False Then ' do this if array is a word
  25.                 If aryTextFile(i).ToLower = Main.SrchBox.Text.ToLower Then
  26.  
  27.                     count = count + 1
  28.                     aryresult(count) = projectdetails 'records results of search in an array
  29.  
  30.                 End If
  31.  
  32.  
  33.             End If
  34.  
  35.             If IsNumeric(aryTextFile(i).Chars(0)) = True Then
  36.  
  37.                 projectno = aryTextFile(i)
  38.                 aryTextFile(i) = "" ' deletes project no. from array so that only project name is left when joined later
  39.             End If
  40.  
  41.  
  42.         Next i
  43.  
  44.         If count > 0 Then
  45.             condition = "Found"
  46.             For i = 0 To count
  47.  
  48.                 If aryresult(i) = "" = False Then ' add multiple results to listbox
  49.                     List.ListBox1.Items.Add(aryresult(i))
  50.                     List.Visible = True
  51.                 End If
  52.  
  53.             Next
  54.  
  55.         End If
  56.  
  57.  
  58.  
  59.         projectname = String.Join(" ", aryTextFile)
  60.         projectname = projectname.TrimStart(" ")
  61.  
  62.  
  63.  
  64.  
  65.         'Compare full name or number to search details and display
  66.         If count = 0 Then
  67.             If projectname.ToLower = Main.SrchBox.Text.ToLower Or projectno = Main.SrchBox.Text Then
  68.  
  69.                 Main.TextBox1.Text = projectname
  70.                 Main.TextBox2.Text = projectno
  71.                 Main.GroupBox1.Visible = True
  72.                 Main.CostingToolStripMenuItem.Visible = True
  73.                 Main.LblType.Text = ("'" & System.IO.Path.GetDirectoryName(foldername) & "'")
  74.                 condition = "Found"
  75.                 Main.showpix()
  76.             End If
  77.         End If
  78.  
  79.  
  80.  
  81.     End Sub
Sep 25 '07 #5
Killer42
8,435 Expert 8TB
It would help if you tell us which line throws the error. I can see possibilities at...
  • Line 19, if more than 10 (or is it 11?) things in projectdetails.
  • Line 20 if some option caused arrays to start numbering at 1 (as they should!) instead of 0.
  • Perhaps line 25 if SearchBox is empty for any reason?
  • Line 28 if count is more than 50.
  • Line 35 is just silly - it should be an Else.
Keep in mind, of course, that I'm a VB6 developer and not familiar with the .Net versions.
Sep 25 '07 #6
hidara
7
It would help if you tell us which line throws the error. I can see possibilities at...
  • Line 19, if more than 10 (or is it 11?) things in projectdetails.
  • Line 20 if some option caused arrays to start numbering at 1 (as they should!) instead of 0.
  • Perhaps line 25 if SearchBox is empty for any reason?
  • Line 28 if count is more than 50.
  • Line 35 is just silly - it should be an Else.
Keep in mind, of course, that I'm a VB6 developer and not familiar with the .Net versions.
thank you for your help. I've just picked up vb as a language recently and still having trouble with it.I agree with your point about line 35 and looking at this I found the error. Someone had set up a folder with three blank spaces in a row in the project name.this left two empty arrays when I split the project at the spaces which seemed to be the problem.Ive just added a few lines to keep increasing the index of the array by 1 if it is empty until the upper bound is reached. thank you all again.
Sep 25 '07 #7
Killer42
8,435 Expert 8TB
Glad we could help. :)

(And I'm gradually picking up VB.Net syntax along the way...)
Sep 26 '07 #8
hariharanmca
1,977 1GB
Here is the area of my code which is causing trouble. It ...............
Expand|Select|Wrap|Line Numbers
  1.         Dim aryTextFile() As String
  2.         Dim aryresult(50) As String 'if count over 50 create msgbox error
  3.         Dim projectdetails As String = System.IO.Path.GetFileName(foldername)
  4.         Dim projectname As String
  5.         Dim projectno As String = ""
  6.         Dim intArrSize As Integer
  7.  
  8.         projectdetails = projectdetails.Replace(" - ", " ") ' deletes symbols 
  9.         intArrSize = UBound(projectdetails.Split(" ") )
  10.         ReDim aryTextFile(intArrSize) As String
  11.         aryTextFile = projectdetails.Split(" ") ' split at each space
  12.  
This changes you have to do it in your code
when ever you are going to use split method you should not fix the array size.
Sep 26 '07 #9

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

Similar topics

0
by: Eugene | last post by:
Hello all, I've been trying to figure this out for a few days now, and still have no clue what's going on... I have a few related tables in MS Access (Clients, Cars, Sales), and a datagrid,...
50
by: jacob navia | last post by:
As everybody knows, the C language lacks a way of specifying bounds checked arrays. This situation is intolerable for people that know that errors are easy to do, and putting today's powerful...
26
by: Method Man | last post by:
Say I have the following: int main(void) { char* p, q; p = (char*) malloc(sizeof(char)*10); q = (p + 100) - 99; /* legal? */ free(q - 1); /* legal? */ .... return 0; }
0
by: scotthutchinson | last post by:
I have a .NET Remoting object hosted in IIS6 on Windows Server 2003 (happens before and after installing SP1) at an endpoint (ASP.NET application virtual folder) named "CompanyXYZReporting". The...
2
by: Denis C | last post by:
Hi there, I'm trying to convert part of a byte array into a series of fixed length strings but half way through the for loop I get an error that I'm accessing outside the buffer bounds. The...
4
by: Antoine | last post by:
Herfried and Cor:- I used tracing and actually tracked down the code that was causing the problem most likely. I wonder if you wanted to comment on it. Also I wonder if there is a better way...
0
by: Smokey Grindle | last post by:
This is just a wierd one... I am trying to draw the sub items in the drawitem event of the list view in owner drawn mode (because of documented W32 rendering bugs) instead of in two seperate items...
11
by: Frederick Gotham | last post by:
In another thread recently, there was discussed the accessing of array indices which were out of bounds. Obviously, the following code is bogus: int arr; arr = 4; Take the following snippet...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
2
by: sam.barker0 | last post by:
Hi , I am having 3 functions.When I step through when func b returns to funca.it throws an error "cannot find function bounds" funca() { .... ... funcb(); }
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.