Re: String Split Headache
Don't use that Split function. It's a hangover from VB6. Use the .NET-specific Split method, which is a member of the String object itself:
vb.net Code:
Dim myArray = myString.Split("."c)
That Split method is overloaded so it allows you to split in various ways.
Re: String Split Headache
I did a little more coding and came up with how I wanted to use this, but it throws a bunch of exceptions at me, even though the code works fine.
Code:
totalPriceString = totalPrice.ToString
Dim priceArray() = totalPriceString.Split("."c)
If ((priceArray IsNot Nothing) And (UBound(priceArray) = 0)) Then ' I have no decimals
totalPriceString = totalPrice.ToString & ".00"
salesTaxString = salesTax.ToString & ".00"
ElseIf ((priceArray IsNot Nothing) And (UBound(priceArray) = 1)) Then ' I have one or two decimals already
If (priceArray(1).Length = 1) Then
totalPriceString = totalPrice.ToString & "0"
salesTaxString = salesTax.ToString & "0"
End If
End If
The exceptions:
Code:
A first chance exception of type 'System.IndexOutOfRangeException' occurred
A first chance exception of type 'System.NullReferenceException' occurred
A first chance exception of type 'System.NullReferenceException' occurred
A first chance exception of type 'System.NullReferenceException' occurred
A first chance exception of type 'System.NullReferenceException' occurred
A first chance exception of type 'System.NullReferenceException' occurred
A first chance exception of type 'System.IndexOutOfRangeException' occurred
A first chance exception of type 'System.IndexOutOfRangeException' occurred
A first chance exception of type 'System.IndexOutOfRangeException' occurred
A first chance exception of type 'System.IndexOutOfRangeException' occurred
I understand what the exceptions mean, just not why I am getting them in this case when I specifically checked to prevent them...
Re: String Split Headache
If all you're getting is a message that an exception was thrown then that means that the exception is thrown and caught in Framework code, so it's not your issue. You aren't actually catching any of these exceptions yourself are you? You might also try extending that code out so that every line does just one thing and then stepping through it line by line. You can then determine exactly which line each exception is caused by.
Also, that UBound function is also a VB6 holdover. You should use the GetUpperBound method of the array itself.
Re: String Split Headache
Wow, why is the documentation telling me to use all these VB6 functions? Once I used GetUpperBound all my errors went away. Thanks a bunch man.