This is part of my specifications and I am having trouble with it.
When converting from one language to another:
a. The words to be converted must be placed into an array with each element of the array containing one word.
b. When converting the words, each word must read from the array and converted.
c. This program must only have one array.
d. A single developer defined procedure must be used to populate the array.
having a little trouble keeping "hold' within the index while trying to move the words into the array
So whatever reason, hold does to -1 and that is what's making the error appear. What can I do to fix this?
Here is my code so far
Option Strict On
Public Class PigLatinForm
Private words(-1) As String
Private Sub exitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles exitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub textBox_GotFocus(sender As Object, e As EventArgs) Handles inputTextBox.GotFocus
inputTextBox.SelectAll()
outputTextBox.SelectAll()
End Sub
Private Sub inputTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles inputTextBox.KeyPress
If e.KeyChar Like "[!a-z0-9 ]" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub aboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles aboutToolStripMenuItem.Click
MessageBox.Show( _
"Pig Latin Converter" _
& ControlChars.NewLine & "" _
& ControlChars.NewLine & "Version 1.00" _
& ControlChars.NewLine & "" _
& ControlChars.NewLine & "by Aaron Anguillara" _
& ControlChars.NewLine & "" _
& ControlChars.NewLine & "Copyright 2014", "About Pig Latin Converter", MessageBoxButtons.OK, _
MessageBoxIcon.None, MessageBoxDefaultButton.Button2)
End Sub
Private Sub PigLatinform_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Private Sub toPigLToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles toPigLToolStripMenuItem.Click
Dim hold As Integer
Dim word As String
Do Until inputTextBox.Text.Length = 0
hold = inputTextBox.Text.IndexOf(" ")
word = inputTextBox.Text.Substring(0, hold)
ReDim Preserve words(words.Length)
words(words.Length - 1) = inputTextBox.Text
Loop
outputTextBox.Text = inputTextBox.Text.ToString
If inputTextBox.Text.StartsWith("aeiou") Then
outputTextBox.Text.EndsWith("--way")
Else
End If
End Sub
End Class
When converting from one language to another:
a. The words to be converted must be placed into an array with each element of the array containing one word.
b. When converting the words, each word must read from the array and converted.
c. This program must only have one array.
d. A single developer defined procedure must be used to populate the array.
having a little trouble keeping "hold' within the index while trying to move the words into the array
So whatever reason, hold does to -1 and that is what's making the error appear. What can I do to fix this?
Here is my code so far
Option Strict On
Public Class PigLatinForm
Private words(-1) As String
Private Sub exitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles exitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub textBox_GotFocus(sender As Object, e As EventArgs) Handles inputTextBox.GotFocus
inputTextBox.SelectAll()
outputTextBox.SelectAll()
End Sub
Private Sub inputTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles inputTextBox.KeyPress
If e.KeyChar Like "[!a-z0-9 ]" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub aboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles aboutToolStripMenuItem.Click
MessageBox.Show( _
"Pig Latin Converter" _
& ControlChars.NewLine & "" _
& ControlChars.NewLine & "Version 1.00" _
& ControlChars.NewLine & "" _
& ControlChars.NewLine & "by Aaron Anguillara" _
& ControlChars.NewLine & "" _
& ControlChars.NewLine & "Copyright 2014", "About Pig Latin Converter", MessageBoxButtons.OK, _
MessageBoxIcon.None, MessageBoxDefaultButton.Button2)
End Sub
Private Sub PigLatinform_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Private Sub toPigLToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles toPigLToolStripMenuItem.Click
Dim hold As Integer
Dim word As String
Do Until inputTextBox.Text.Length = 0
hold = inputTextBox.Text.IndexOf(" ")
word = inputTextBox.Text.Substring(0, hold)
ReDim Preserve words(words.Length)
words(words.Length - 1) = inputTextBox.Text
Loop
outputTextBox.Text = inputTextBox.Text.ToString
If inputTextBox.Text.StartsWith("aeiou") Then
outputTextBox.Text.EndsWith("--way")
Else
End If
End Sub
End Class