If you’ve ever had problems with using looping on an N1 loop extracting the ship-to information if the ship-to is notin the first loop, this might help.

Old way of doing it.

New way of doing it.

Here’s the functiod logic.

Public Function ReturnSTInfo_1(ByVal IterationSTring_1 As String, ByVal N104_1 As String) As String
Dim BeginningIndexValue_1 As Integer
Dim EndingIndexValue_1 As Integer
Dim LengthOfElement_1 As Integer
BeginningIndexValue_1 = System.Convert.ToInt32(IterationSTring_1.Substring((IterationSTring_1.IndexOf(“ST”) – 2), 1))
EndingIndexValue_1 = BeginningIndexValue_1 + 1
If N104_1.IndexOf(System.Convert.ToString(EndingIndexValue_1) + “*”) = -1 Then

Return N104_1.Substring((N104_1.IndexOf(System.Convert.ToString(BeginningIndexValue_1) + “*”) + 2))

Else

LengthOfElement_1 = (N104_1.IndexOf(System.Convert.ToString(EndingIndexValue_1) + “*”)) – (N104_1.IndexOf(System.Convert.ToString(BeginningIndexValue_1) + “*”) + 2)
Return N104_1.Substring((N104_1.IndexOf(System.Convert.ToString(BeginningIndexValue_1) + “*”) + 2), LengthOfElement_1)

End If
End Function