Note that there are some explanatory texts on larger screens.

plurals
  1. PO'StartIndex cannot be less than zero.' when trying to load a form in vb
    text
    copied!<p>I have recently made some changes to one of the subs within a form of my vb project and I am now getting an error whilst attempting to load the form. I have little idea what <code>start index</code> or <code>Parameter name</code> are with relation to a form, so don't where to start looking to solve this issue. Here is the error message I get:</p> <pre><code>An error occurred creating the form. See Exception.InnerException for details. The error is: StartIndex cannot be less than zero. Parameter name: startIndex </code></pre> <p>The Sub that I have made changes to is the last sub in the code below called <code>TextBox1changed_textchanged</code>. I have added all but the last 5 lines as to limit the characters that can be put into the text box. This new code is edited from another forum page so I assume it should work correctly, but I can't be sure as the form will no longer run.</p> <pre><code>Public Class frmAddQuantity Private Sub frmFieldMaster_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load cmbStateRateSumRatio.Items.Clear() cmbStateRateSumRatio.Items.Insert(0, "State") cmbStateRateSumRatio.Items.Insert(1, "Rate") cmbStateRateSumRatio.Items.Insert(2, "Sum") cmbStateRateSumRatio.Items.Insert(3, "Ratio") End Sub Private Sub bttAddQUAtoDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttAddQUAtoDatabase.Click AddQuantity("'" &amp; TextBox1.Text &amp; "', '" &amp; TextBox2.Text &amp; "', '" &amp; cmbStateRateSumRatio.Text &amp; "'") InitialiseAll() frmFieldMaster.InitialiseNewParameter() Me.Close() End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged If TextBox2.Text &lt;&gt; "Enter SI Units" Then If cmbStateRateSumRatio.SelectedIndex &lt;&gt; -1 Then bttAddQUAtoDatabase.Enabled = True End If End If End Sub Private Sub cmbStateRateSumRatio_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbStateRateSumRatio.SelectedIndexChanged If TextBox1.Text &lt;&gt; "Enter Quantity" Then If TextBox2.Text &lt;&gt; "Enter SI Units" Then bttAddQUAtoDatabase.Enabled = True End If End If End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged Dim charactersAllowed As String = " abcdefghijklmnopqrstuvwxyz1234567890^-*()." Dim Text As String = TextBox2.Text Dim Letter As String Dim SelectionIndex As Integer = TextBox2.SelectionStart Dim Change As Integer Letter = TextBox2.Text.Substring(SelectionIndex - 1, 1) If Letter = "/" Then Text = Text.Replace(Letter, "^(-") SelectionIndex = SelectionIndex - 1 End If Letter = TextBox2.Text.Substring(SelectionIndex - 1, 1) If charactersAllowed.Contains(Letter) = False Then Text = Text.Replace(Letter, String.Empty) Change = 1 End If TextBox2.Text = Text TextBox2.Select(SelectionIndex - Change, 0) If TextBox1.Text &lt;&gt; "Enter Quantity" Then If cmbStateRateSumRatio.SelectedIndex &lt;&gt; -1 Then bttAddQUAtoDatabase.Enabled = True End If End If End Sub </code></pre> <p>End Class</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload