Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index was outside the bounds of the array 1

Status
Not open for further replies.

DimMeAsNewbie

Technical User
Mar 17, 2007
20
GB
Hey Guys!
It's me again, thanks for you help to my previous error, unfortunately i've a new devil as in the error above, i surely must be cursed
Can anyone help identify what's causing the above error, error is yellow highlighted at line " If word(i) = input Then" of the code?


Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
input = e.KeyChar
For i = 0 To l - 1
If word(i) = input Then ERROR IS HIGHLIGHTED HERE
ostr(i * 2) = word(i)
ostr.Replace(ostr(i * 2), word(i))
found = 1
End If
Next
Label4.Text = input
If found = 0 Then

End If

End Sub
 
Thanks ThatRickGuy, but i've already got this loop in my form handler and l is set to word length.

For i = 0 To word.length-1
 
I've got

Dim i As Interger

And then the loop
For i = 0 To word.length = 1

What do you reckon i should set the value of i to?
 
when the exception occurs you should be able to hover the mouse over 'i' and the value should pop-up. Or else, open the Immediate window, inside it type ?i.

I'm guessing i=0, which means that the word array is empty.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks ThatRickyGuy.

So basically i should have as many loops as my longest word in the file.txt, is that right?, my longest is 12 letters so does this mean i should have i values 0-11? , and Me.Invalidate after each loop.

Thanks!
 
No idea, I don't know what the rest of your code is doing, so I can't say. But you should probably check the word.length before the loop. like:

Code:
if word.length > 0 then
  'your code here
end if

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks!

Basically what the rest of my code is doing is reading through a text file + and then randomly selectes a word that is read character by character. On the form i have got a label that has got about 12 underscores to accommodate letters.If a user presses right key the letter should appear in the label and on the right underscore, Else display somewhere else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top