类型的值不能转换为字符串VB

时间:2019-03-24 16:52:03

标签: vb.net

严重性代码描述项目文件行抑制状态 错误BC30332类型'Integer()'的值不能转换为'String()',因为'Integer'不是从'String'派生的。 AlgorithmMk(强大版)

如何解决?该行:TxtGamblerOutput.AppendText(String.Join(" ", output.ToArray) & vbCrLf)

Private Sub BttGamblerInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BttGamblerInput.Click
        On Error Resume Next
        Dim value As Integer
        Dim values As New List(Of String)
        For Each strValue As String In TxtGamblerImput.Text.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
            If Integer.TryParse(strValue.Trim, value) Then
                values.Add(value)
            End If
        Next
        Dim curRev As String
        Dim Rev As New Revision("-0+", New String("-", values.Count))
        Dim output As New List(Of Integer)
        TxtGamblerOutput.Clear()
        curRev = Rev.CurrentRevision
        While curRev.Length = values.Count
            output.Clear()
            For i As Integer = 0 To curRev.Length - 1
                Select Case curRev(i)
                    Case "-"
                        output.Add(values(i) - 1)
                    Case "0"
                        output.Add(values(i))
                    Case "+"
                        output.Add(values(i) + 1)
                End Select
            Next
            TxtGamblerOutput.AppendText(String.Join(" ", output.ToArray) & vbCrLf)
            curRev = Rev.NextRevision
        End While
    End Sub

1 个答案:

答案 0 :(得分:0)

我不知道Revision类是什么..并且问题可能在那里,但是您的For..Next循环可能是问题..

尝试如下添加Integer.Parse

正如@andrewmorton所说。您应该始终在所有代码的顶部使用Option Strict On,或在Google上更改默认设置以更改设置。而且永远不要使用On Error Resume Next。这是旧代码,适合懒惰的坏程序员。

您还会注意到,我在您的c语句中的字符串之后添加了Select Case。这是为了让编译器知道您正在检查Char类型,而不是String类型,否则,它也会与您进行比较,然后您就拥有Option Strict On

For i As Integer = 0 To curRev.Length - 1
    Select Case curRev(i)
        Case "-"c
            output.Add(Integer.Parse(values(i)) - 1)
        Case "0"c
            output.Add(Integer.Parse(values(i)))
        Case "+"c
            output.Add(Integer.Parse(values(i)) + 1)
    End Select
        Next