Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从“字符串”到“布尔”类型的转换无效_Vba - Fatal编程技术网

Vba 从“字符串”到“布尔”类型的转换无效

Vba 从“字符串”到“布尔”类型的转换无效,vba,Vba,我最近在为一个学校加密程序编写的代码中遇到了这个问题,我花了几个小时试图绕过这个错误,但我似乎无法让它工作,你怎么了 TextBox1.Text = TextBox1.Text.ToLower Dim input As String = TextBox1.Text Dim charPos As Integer = 0 Dim Cipher As String = "" Dim x As Boolean Dim Random As Boolean

我最近在为一个学校加密程序编写的代码中遇到了这个问题,我花了几个小时试图绕过这个错误,但我似乎无法让它工作,你怎么了

    TextBox1.Text = TextBox1.Text.ToLower
    Dim input As String = TextBox1.Text
    Dim charPos As Integer = 0
    Dim Cipher As String = ""
    Dim x As Boolean
    Dim Random As Boolean

    If input = "" Then
        MsgBox("Please enter your text for encryption including only characters A-Z")
    End If

    Select Case Random
        Case 0
            Random = ComboBox1.SelectedItem.ToString()
        Case 1
            Random = "selection1"
            x = True
        Case Else
            x = False
    End Select

    If x = True Then
        Dim alphabet As String = "abcdefghij klmnopqrstuvwxyz"
        Dim code As String = "kxgtlmpqbwcnderfahjusvi yoz"

        For i = 0 To input.Length - 1

            Try
                charPos = alphabet.IndexOf(input(i))
                Cipher = Cipher & code(charPos)
            Catch ex As Exception
                MsgBox("Please enter your text for encryption including only characters A-Z")
            End Try
        Next i
        TextBox1.Text = (Cipher)
    Else

    End If
End Sub
Visual Basic中的实际错误本身为

Random = ComboBox1.SelectedItem.ToString()

很抱歉,如果这很难理解,我对Stackoverflow和VB都是新手,因此如果您不太了解它,请发表评论:

下面是一个使用您的代码的示例

    TextBox1.Text = TextBox1.Text.ToLower
    Dim input As String = TextBox1.Text
    Dim charPos As Integer = 0
    Dim Cipher As String = ""

    If input = "" Then
        MsgBox("Please enter your text for encryption including only characters A-Z")
    End If

    If ComboBox1.SelectedIndex = 0 Then
        Dim alphabet As String = "abcdefghij klmnopqrstuvwxyz"
        Dim code As String = "kxgtlmpqbwcnderfahjusvi yoz"

        For i = 0 To input.Length - 1

            Try
                charPos = alphabet.IndexOf(input(i))
                Cipher = Cipher & code(charPos)
            Catch ex As Exception
                MsgBox("Please enter your text for encryption including only characters A-Z")
            End Try
        Next i
        TextBox1.Text = (Cipher)
    Else

    End If
End Sub

该行显示的错误是什么?