sub string out of range error 9

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • husseinspiky
    New Member
    • Apr 2015
    • 3

    sub string out of range error 9

    Code:
    Public Function LinkFileNumericSplitter(strTextInput) As String
    On Error GoTo Err_LinkFileNumericSplitter
        
        Dim varResult As Variant
        Dim i As Long
        Dim strRowSource As String
        Dim strLinkFile As String
        Dim varSubTextInput As String
        
        If strTextInput = "Link File" Then
            GoTo Exit_LinkFileNumericSplitter
        Else
            If InStr(strTextInput, "Link File") > 0 Then
                varSubTextInput = Replace(strTextInput, "Link File", " ")
                strLinkFile = Mid(varSubTextInput, InStr(varSubTextInput, " "), Len(varSubTextInput))
                varResult = Split(strLinkFile, ",")
                 i = 0
                    Do While i <= UBound(varResult) And IsNumeric(varResult(i))
                        strRowSource = strRowSource + varResult(i) & ";"
                       ' CheckLinkFileExists (varResult(i))
                        i = i + 1
                        Debug.Print i & strRowSource
                    Loop
            End If
        End If
         
         LinkFileNumericSplitter = strRowSource
         
          
    Exit_LinkFileNumericSplitter:
        Exit Function
    
    Err_LinkFileNumericSplitter:
        MsgBox Err.Description
        Resume Exit_LinkFileNumericSplitter
    End Function
    Last edited by Rabbit; Aug 13 '15, 08:25 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Try changing
    Code:
    Do While i <= UBound(varResult) And IsNumeric(varResult(i))
    to
    Code:
    Do While i < UBound(varResult) And IsNumeric(varResult(i))
    because the first array element is at index zero, so the last entry in the array is a Ubound(array)-1.

    Although your code works for me in version 2013 I recall some problems with that in earlier versions.

    You could identify the specific line causing the error by using Resume Next after the error display. Then use the debugger to step to the line following the line that caused the error.

    Also, put your code in between code tags for readability. (even though button for that feature does not seem to be working for me right now! You can add them manually using [ code ] and [ /code ]) without the extra spaces after [

    Jim
    Last edited by jimatqsi; Aug 13 '15, 07:36 PM. Reason: fix code tags

    Comment

    • husseinspiky
      New Member
      • Apr 2015
      • 3

      #3
      thank you so much jim for your response i used to do that

      Code:
      Do While i < UBound(varResult) And IsNumeric(varResult(i))


      but the reason why i change to the other one is that when i enter the string and try to split the numbers the output is incorrect
      for example :
      let say that the input string is ("Link File 3232,2323,444,4 543")
      so the out put is ganna be (3232;2323;444) and it passed the last number
      so what do you think?
      thank you again

      Comment

      Working...