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

Out of bounds error?

P: 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
Share this Question
Share on Google+
8 Replies


hariharanmca
100+
P: 1,977
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
Expert 100+
P: 1,445
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

P: 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

P: 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

Expert 5K+
P: 8,434
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

P: 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

Expert 5K+
P: 8,434
Glad we could help. :)

(And I'm gradually picking up VB.Net syntax along the way...)
Sep 26 '07 #8

hariharanmca
100+
P: 1,977
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

Post your reply

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