Results 1 to 7 of 7

Thread: Runtime error 5

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    54

    Runtime error 5

    This question is probably too general, but can somebody give me an idea of what would cause me to get a

    Runtime error 5: Invalid procedure call or argument?

    The debugger is highlighting this line of code:
    sFileName = Mid$(txtNames.Text, charOffset + 1, LineLength)

    Thanks to anybody that answers

  2. #2
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    you must be sure that all of the vars are known in your code
    VB Code:
    1. Mid$(txtNames.Text, charOffset + 1, LineLength)

    like charOffset and LineLingth
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    54
    This is the entire function if it helps..

    VB Code:
    1. Public Sub ReadNames()
    2. Dim sFileName As String
    3. Dim Lines
    4. Dim WinH As Long
    5. Dim i As Integer
    6. Dim LineLength As Long
    7. Dim charOffset As Long
    8.  WinH = txtNames.hWnd
    9.     Lines = SendMessage(WinH, EM_GETLINECOUNT, 0, 0)
    10.     For i = 0 To Lines - 1
    11.         charOffset = SendMessage(WinH, EM_LINEINDEX, i, 0)
    12.         LineLength = SendMessage(WinH, EM_LINELENGTH, charOffset, 0)
    13.         sFileName = Mid$(txtNames.Text, charOffset + 1, LineLength)
    14.         If sFileName = cboNickName.Text Then GoTo Repeat
    15.         sFileName = Rep(sFileName, "=", "")
    16.         sFileName = Rep(sFileName, "G,", "")
    17.         sFileName = Rep(sFileName, "H,", "")
    18.         sFileName = Rep(sFileName, "U,", "")
    19.         sFileName = Rep(sFileName, "R,", "")
    20.         sFileName = Rep(sFileName, "G,", "")
    21.         sFileName = Rep(Rep(Rep(sFileName, ".", ""), "@", ""), "+", "")
    22.         If sFileName <> "" Then lstNames.AddItem Trim(sFileName)
    23. Repeat:
    24.     Next i
    25. End Sub

  4. #4
    Lively Member bumbala's Avatar
    Join Date
    Sep 2002
    Posts
    111
    One of your arguments is invalid. Make sure charOffset + 1 or LineLength does not return any negative value.

  5. #5
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    And charOffset +1 isn't bigger than the length of your string
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    54
    Ah hah!

    I found out, by doing MsgBox <variables>, that

    VB Code:
    1. sFileName = Mid$(txtNames.Text, charOffset + 1, LineLength)

    Is returning NULL!

    Does Anybody know why it'd be doing this.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Your problem almost certainly is that charOffset + 1 is either larger than the length of your text or it is negative. To find the problem, forget msgboxes (although they can be useful in debugging sometimes) and use the debugger. If you've used the debugger before you probably know how to do all this, but here is what to do.
    • Set a breakpoint on the Mid statement line by placing the cursor on the line and pressing F9
    • Run the program
    • When the program stops at the line, highlight charOffset + 1, press Shift-F9 and note the value. If it's negative then that's the problem.
    • If it isn't then press Ctrl-g to open the Immediate window
    • Type ?len(txtNames.Text), press Enter and you will probably find that the length is less then the value found in the previous step

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width