Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 5 - invalud procedure call or argument

Status
Not open for further replies.

nickske80

Programmer
Aug 2, 2003
55
BE
Hello everybody,

I am trying to create a Text encoder - decoder using the rail fence technique.
But I get a runtime error when I try to decode the text.

I can 't seem to find the problem.
Can anybody help me?

here is the code.

Private Function decode2(ByVal strCode As String, ByVal key As String) As String

Dim i As Integer
Dim j As Integer
Dim intHulp As Integer

decode2 = Space(Len(strCode))
intHulp = 1

For i = 0 To key - 1
For j = 1 To Len(strCode) Step key
Mid(decode2, i + j, 1) = Mid(strCode, intHulp, 1)
intHulp = intHulp + 1
Next j
Next i

end function

thanx for replying.
 
For i = 0 To key - 1
For j = 1 To Len(strCode) Step key

key is a string. Both the above statements would require key to be a numeric variable. Should it be:

For i = 0 To Len(key) - 1

It also looks like you should use Option Explicit which will enable data type mismatch errors to be caught at compile time.

Paul Bent
Northwind IT Systems
 
hello paulbent,

I use the option explicit but didn 't copy it to the thread.

And for the other thing you 've said.

I replaced it to :

For i = 0 To Int(key) - 1

and I get the same error.

It works sometimes.
But when you set the key to 5 and use a word with length 7 (e.g.CYPHERS) it returns the runtime error.

Thanx for replying so fast.
 
sorry for bothering you guys.
I found the answer to my problem myself.

It should have been :


For i = 0 To Int(Left(key, 1)) - 1
For j = 1 To Len(strCode) - i Step Int(Left(key, 1))

thanx to everybody anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top