类型为' System.IndexOutOfRangeException'的未处理异常发生在Encrypt.exe中

时间:2017-02-06 20:23:01

标签: vb.net encryption visual-studio-2015

    Dim word As String = TextBox3.Text
    Dim letter As Char = ""
    Dim place As Integer = 0
    Dim placeLetter As String = ""
    Dim minus As Integer = 0
    Dim minusLetter As String = ""

    placeLetter = Microsoft.VisualBasic.Right(word, 1)
    place = SPInvert(placeLetter) 'turns the letter in to a number. eg - a = 1 , b = 2 
    minusLetter = word.Chars(place)
    minus = SPInvert(minusLetter) 'turns the letter in to a number. eg - a = 1 , b = 2  ' Error is here

'在这下面是功能。

函数SPInvert(ByVal RAND As String)As Integer

    Dim cl As String = RAND
    Dim cn As Integer = 0

    If cl = "a" Then
        cn = 1
    ElseIf cl = "b" Then
        cn = cn & 2
    ElseIf cl = "c" Then
        cn = cn & 3
    ElseIf cl = "d" Then
        cn = cn & 4
    ElseIf cl = "e" Then
        cn = cn & 5
    ElseIf cl = "f" Then
        cn = cn & 6
    ElseIf cl = "g" Then
        cn = cn & 7
    ElseIf cl = "h" Then
        cn = cn & 8
    ElseIf cl = "i" Then
        cn = cn & 9
    ElseIf cl = "j" Then
        cn = cn & 10
    ElseIf cl = "k" Then
        cn = cn & 11
    ElseIf cl = "l" Then
        cn = cn & 12
    ElseIf cl = "m" Then
        cn = cn & 13
    ElseIf cl = "n" Then
        cn = cn & 14
    ElseIf cl = "o" Then
        cn = cn & 15
    ElseIf cl = "p" Then
        cn = cn & 16
    ElseIf cl = "q" Then
        cn = cn & 17
    ElseIf cl = "r" Then
        cn = cn & 18
    ElseIf cl = "s" Then
        cn = cn & 19
    ElseIf cl = "t" Then
        cn = cn & 20
    ElseIf cl = "u" Then
        cn = cn & 21
    ElseIf cl = "v" Then
        cn = cn & 22
    ElseIf cl = "w" Then
        cn = cn & 23
    ElseIf cl = "x" Then
        cn = cn & 24
    ElseIf cl = "y" Then
        cn = cn & 25
    ElseIf cl = "z" Then
        cn = cn & 26
    End If
    Return cn
End Function

运行此代码块时,它会失败并给我这个错误: 类型为' System.IndexOutOfRangeException'的未处理异常发生在Encrypt.exe中附加信息:索引超出了数组的范围。

0 个答案:

没有答案