arrayNumber = Left(strData, InStr(1, strData, "\") - 1)
Hope that makes sense
Well, you know, if you have to tell another programmer, I hope that it makes sense, you've got problems. Of course, that may depend on the programmer. But there's a simple formula for programming that should be followed: KISS.
I still can't make sense of that code. I still remember my old programming teacher telling me when I provided a very complex solution to a simple problem, "Keep it Simple Stupid!"
But this is what I'm guessing. You send a string: e.g. "1\some file data" You pull the number one with your code. That happens to be an integer. And I assume because there are only numbers before the "\" that you always extract integers in string form. And because the string can be converted by the compiler to a long, it doesn't throw an error.
In keeping with the paradigm of KISS--you did ask for tips for more robust code--I would simplify that code.
Private Sub SortNewData(ByVal StrSortcode As String, ByVal strData As String)
' Change that to the following
Private Sub SortNewData(ByVal StrSortcode As String, ByVal strData As String, MyArrayNumber as Long)
If you already know what the ArrayNumber is, why not just send it?
Add another parameter to your function. And then you wouldn't have to write extra code to extract the file data either. Just send the data as a string without any extra identifying characters. You could eliminate about 2 or 3 lines of code in that one Select Case statement.
That would be simpler. And if you had to try to figure out 2 years from now what you were doing, it wouldn't be a problem.
A common problem with programmers is that they write complex solutions for simple problems. The code may seem impressive at the time, but all that complexity can lead to unintelligible and unmanageable code down the road. And that means spending extra unneeded hours to sort through solutions that should have been written simply to begin with. Extra hours translates into extra money. And that's not a good thing.
Sometimes our minds get trapped in 'complex' mode. We have to continually remind ourselves to keep it simple. The simpler the better.
I haven't had time to analyze the rest of the code. I was stuck there. But I assume your complex solution works, but why is the data corrupt? Put a breakpoint at that point and step through it with the F8 checking your variables as you go to see if you're program is processing the data correctly.
If you consistently come up with corrupt data in a certain situation, that provides a perfect condition to use a breakpoint and the F8 function key to step through that section of the code you believe to be at fault to check the data to see where the problem lies.