-1

There is a weird error when I try to close my Windows Form... I am trying to do a string manipulation of this string: ABEL, SCOTT - 1472 (COL) when the ComboBox Selected Item changed. It is able to work as you can see from the debugger below, but when the form closes, an error throws.

My ComboBox items is populated by a Data Source with the Me.GetRunnersTableAdapter.Fill(Me.WSCDbDataSet.GetRunners) function.

Is this a bug?

enter image description here

iamhx
  • 472
  • 6
  • 24
  • Just from your screen it's pretty obvious what the error is: 'cmbRunner.text = ""', and myLastName is 0, which leave line 27 something like `LastName.Text = Strings.Left("", -1)` . Of course that will raise an error because of the -1 argument. And in this case, instead of using Left, Right or Mid, i suggest you use Split. – HaPhan Jul 04 '16 at 08:32

1 Answers1

-1

I've gotten it to work by using Try, Catch.

Dim myLastName
myLastName = InStr(1, cbRunner.Text, ",")

Dim myFirstName
myFirstName = InStr(myLastName + 2, cbRunner.Text, "-")

Dim myBibNumber
myBibNumber = InStr(myFirstName + 2, cbRunner.Text, "(")


Try
LastName.Text = Trim$(Strings.Left(cbRunner.Text, myLastName - 1))
FirstName.Text = Trim$(Mid(cbRunner.Text, myLastName + 2, myFirstName - myLastName - 2))
BibNumber.Text = Trim$(Mid(cbRunner.Text, myFirstName + 2, myBibNumber - myFirstName - 2))
Catch ex As ArgumentException

End Try
iamhx
  • 472
  • 6
  • 24