This is the code I came up with but am getting the error "Index and length must refer to a location within the string.
Parameter name: length" at run time when I click the button. Any help would be appreciated as I have spent hours on this and searched all over the web and havent had any luck finding any examples.
Thanks!
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim word As String = CStr(TextBox1.Text)
Dim length As Integer = word.Length - 1
Dim track As Integer = 0
Dim letter1 As String
Dim letter2 As String
For i As Integer = 0 To length Step 1
letter1 = word.Substring(i, 1)
letter2 = word.Substring(i + 1, 1)
If letter1 > letter2 Then
track = (track + 1)
End If
Next i
If track = length Then
TextBox2.Text = "The letters of this word are in alphabetical order!"
Else : TextBox2.Text = "The letters of this word are NOT in alphabetical order! Sorry!"
End If
End Sub
End Class

New Topic/Question
Reply



MultiQuote








|