|
-
Sep 20th, 2002, 07:17 AM
#1
Thread Starter
Member
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
-
Sep 20th, 2002, 07:22 AM
#2
Frenzied Member
you must be sure that all of the vars are known in your code
VB Code:
Mid$(txtNames.Text, charOffset + 1, LineLength)
like charOffset and LineLingth
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Sep 20th, 2002, 07:23 AM
#3
Thread Starter
Member
This is the entire function if it helps..
VB Code:
Public Sub ReadNames()
Dim sFileName As String
Dim Lines
Dim WinH As Long
Dim i As Integer
Dim LineLength As Long
Dim charOffset As Long
WinH = txtNames.hWnd
Lines = SendMessage(WinH, EM_GETLINECOUNT, 0, 0)
For i = 0 To Lines - 1
charOffset = SendMessage(WinH, EM_LINEINDEX, i, 0)
LineLength = SendMessage(WinH, EM_LINELENGTH, charOffset, 0)
sFileName = Mid$(txtNames.Text, charOffset + 1, LineLength)
If sFileName = cboNickName.Text Then GoTo Repeat
sFileName = Rep(sFileName, "=", "")
sFileName = Rep(sFileName, "G,", "")
sFileName = Rep(sFileName, "H,", "")
sFileName = Rep(sFileName, "U,", "")
sFileName = Rep(sFileName, "R,", "")
sFileName = Rep(sFileName, "G,", "")
sFileName = Rep(Rep(Rep(sFileName, ".", ""), "@", ""), "+", "")
If sFileName <> "" Then lstNames.AddItem Trim(sFileName)
Repeat:
Next i
End Sub
-
Sep 20th, 2002, 07:24 AM
#4
Lively Member
One of your arguments is invalid. Make sure charOffset + 1 or LineLength does not return any negative value.
-
Sep 20th, 2002, 07:30 AM
#5
Frenzied Member
And charOffset +1 isn't bigger than the length of your string
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Sep 20th, 2002, 07:50 AM
#6
Thread Starter
Member
Ah hah!
I found out, by doing MsgBox <variables>, that
VB Code:
sFileName = Mid$(txtNames.Text, charOffset + 1, LineLength)
Is returning NULL!
Does Anybody know why it'd be doing this.
-
Sep 20th, 2002, 08:12 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|