I'm trying to finish an assignment for my Introduction to Visual Basic class.
I have to program an application that will determine if a word entered has consecutive letters in the alphabet as a substring of itself. Three examples are T"HI""RST"Y, AF"GH"ANI"ST"AN, and "STU""DE"NT.
This is what I have so far:
However, it doesn't run properly. It says I'm trying to refer to a location that is out of bounds, although I don't see why.Code:Public Class ConsecutiveLettersot 'declare text input as class level variable Dim textInput As String 'delcare substring locations as class level variables Dim locationOne As Integer Dim locationTwo As Integer Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click 'clear read-only boxes lstConsecutiveLetters.Items.Clear() txtConcecutiveAmount.Text = "" 'if the entry was numbers, display error If IsNumeric(txtEntry.Text) = False Then 'entered text is not a number, delcare variable textInput = txtEntry.Text.ToUpper Else 'entry was not letters MessageBox.Show("Please do not enter numbers.", "Error!") 'return early Return End If 'if the entry is less than 2 letters long If txtEntry.Text.Length < 2 Then MessageBox.Show("Entered text must be at least 2 letters long!", "Error!") 'return early Return End If For i = 0 To ((textInput.Length) - 1) locationOne = Asc(textInput.Substring(i, 1)) locationTwo = Asc(textInput.Substring(i + 1, 1)) If locationTwo - locationOne = 1 Then lstConsecutiveLetters.Items.Add(textInput.Substring(i, 1)) End If i += 1 Next End Sub End Class
Any help would be greatly appreciated.
Thank you.




Reply With Quote