Hey guys. i need help. for college i have to have a user enter a string and then split the string into seperate words which i have done. however i also need to find the longest and shortest word which i just can't do and its driving me mad. can someone please have a look at my code below and tell me what i've done wrong. Thanks guys
Private Sub btnQ5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQ5.Click
Dim enterText As String
Dim i As Integer
Dim stringArray() As String
Dim Shortest As String
Dim Longest As String
Dim x As Integer
enterText = InputBox("Please enter some text")
stringArray = enterText.Split(" ")
For i = 0 To stringArray.Length - 1
MsgBox(stringArray(i))
Next
'This is the part i am having trouble with
Shortest = stringArray(LBound(stringArray))
Longest = stringArray(LBound(stringArray))
For x = 0 To stringArray.Length - 1
If Len(Shortest) < Len(stringArray(x)) Then Shortest = stringArray(x)
If Len(Longest) > Len(stringArray(x)) Then Longest = stringArray(x)
Next
lstOut.Items.Add(Shortest)
lstOut.Items.Add(Longest)
End Sub
Private Sub btnQ5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQ5.Click
Dim enterText As String
Dim i As Integer
Dim stringArray() As String
Dim Shortest As String
Dim Longest As String
Dim x As Integer
enterText = InputBox("Please enter some text")
stringArray = enterText.Split(" ")
For i = 0 To stringArray.Length - 1
MsgBox(stringArray(i))
Next
'This is the part i am having trouble with
Shortest = stringArray(LBound(stringArray))
Longest = stringArray(LBound(stringArray))
For x = 0 To stringArray.Length - 1
If Len(Shortest) < Len(stringArray(x)) Then Shortest = stringArray(x)
If Len(Longest) > Len(stringArray(x)) Then Longest = stringArray(x)
Next
lstOut.Items.Add(Shortest)
lstOut.Items.Add(Longest)
End Sub