Results 1 to 4 of 4

Thread: "Procedure call or argument is not valid" error

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    "Procedure call or argument is not valid" error

    Since this is my first post, be sure to use lots of lube ok?

    I have a "working" program for a Vigenère cipher, but I am having an issue that I can't pinpoint. Anytime an accent mark is used in the plain text i get a "Procedure call or argument is not valid" error. So trying to encrypt "Vigenère cipher" for example will not work.

    Using the plaintext "f" with the keyword set as "b" the output is "È". Decryption handles these characters just fine. The following code is my encryption sub:

    Code:
        Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
    
            Dim Key As String = txtKey.Text 'makes the password 
    
            Dim TestString As String 'creates string variable to store encryptable material
            TestString = txtWord.Text 
    
            If Len(Key) <= Len(TestString) Then 'this is run if the key is shorter than the encryptable material
                For i = 0 To (TestString.Length - Key.Length)
                    'concatenates each character of the key string to itself until its length equals TestString length
                    Key = String.Concat(Key, Key.Substring(i, 1))
                Next i
            End If
            'this loop is where the substitution is done
            For i = 1 To TestString.Length
                'convert string characters to character code equivalent and then the values are assigned to TestString
                Mid(TestString, i, 1) = Chr(Asc(Mid(TestString, i, 1)) + Asc(Key.Substring(i, 1)))
            Next i
    
            txtResult.Text = TestString
        End Sub
    The decryption part is just the same except the for loop:
    Code:
            For i = 1 To TestString.Length
                Mid(TestString, i, 1) = Chr(Asc(Mid(TestString, i, 1)) - Asc(Key.Substring(i, 1)))
            Next i
    I hope there is just something small, but us new guys never have that much luck! Thanks in advance.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: "Procedure call or argument is not valid" error

    I guess I should also say that the reason I want to be able to do have these special characters work on the encryption side is so that I could run it through multiple times with multiple key words. Thanks!

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: "Procedure call or argument is not valid" error

    Moved To VB.NET

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: "Procedure call or argument is not valid" error

    I did figure it out on my own if anyone here cares enough about this topic. Turned out to be a stupid error as per usual. It was an out of range issue. I needed to use ChrW() and AscW() in my encryption and decryption subs to get the character codes to be recognized as valid.

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