0

我正在尝试15VB.

稍后,我将不得不将这些15作品提交为完整的图像。

在mintime,我尝试用数字来构建它。一切正常,直到我收到这个消息:

Conversion from string "" to type 'Double' is not valid.

我把它排成一行:

 If butt2.Content = "" Then

这是我的代码:

<pre lang="vb">Class MainWindow

    Private Sub btn1_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
        '2,4
        checkBtn(btn1, btn4)
        checkBtn(btn1, btn2)
        chechSolved()
    End Sub

    Private Sub btn2_Click(sender As Object, e As RoutedEventArgs) Handles btn2.Click
        '1,3,5
        checkBtn(btn2, btn1)
        checkBtn(btn2, btn3)
        checkBtn(btn2, btn5)
        chechSolved()
    End Sub

    Private Sub btn3_Click(sender As Object, e As RoutedEventArgs) Handles btn3.Click
        '2,6
        checkBtn(btn3, btn2)
        checkBtn(btn3, btn6)
        chechSolved()
    End Sub

    Private Sub btn4_Click(sender As Object, e As RoutedEventArgs) Handles btn4.Click
        '1,5,7
        checkBtn(btn4, btn1)
        checkBtn(btn4, btn5)
        checkBtn(btn4, btn7)
        chechSolved()
    End Sub

    Private Sub btn5_Click(sender As Object, e As RoutedEventArgs) Handles btn5.Click
        '2,4,6,8
        checkBtn(btn5, btn2)
        checkBtn(btn5, btn4)
        checkBtn(btn5, btn6)
        checkBtn(btn5, btn8)
        chechSolved()
    End Sub

    Private Sub btn6_Click(sender As Object, e As RoutedEventArgs) Handles btn6.Click
        '3,5,9
        checkBtn(btn6, btn3)
        checkBtn(btn6, btn5)
        checkBtn(btn6, btn9)
        chechSolved()
    End Sub

    Private Sub btn7_Click(sender As Object, e As RoutedEventArgs) Handles btn7.Click
        '4,8
        checkBtn(btn7, btn4)
        checkBtn(btn7, btn8)
        chechSolved()
    End Sub

    Private Sub btn8_Click(sender As Object, e As RoutedEventArgs) Handles btn8.Click
        '5,7,9
        checkBtn(btn8, btn5)
        checkBtn(btn8, btn7)
        checkBtn(btn8, btn9)

        chechSolved()
    End Sub

    Private Sub btn9_Click(sender As Object, e As RoutedEventArgs) Handles btn9.Click
        '6,8
        checkBtn(btn9, btn6)
        checkBtn(btn9, btn8)

        chechSolved()
    End Sub

    Sub checkBtn(ByVal butt1 As Button, ByVal butt2 As Button)

       If butt2.Content = "" Then
            butt2.Content = butt1.Content
            butt1.Content = ""
        End If
    End Sub

    Sub chechSolved()

        If btn1.Content = &quot;1&quot; And btn2.Content = &quot;2&quot; And btn3.Content = &quot;3&quot; And btn4.Content = &quot;4&quot; And btn5.Content = &quot;5&quot; And btn6.Content = &quot;6&quot; And btn7.Content = &quot;7&quot; And btn8.Content = &quot;8&quot; And btn9.Content = &quot;&quot; Then
            MsgBox(&quot;הצלחת&quot;)
        End If
    End Sub



    Sub shuffle()

        Dim a(8), i, j, RN As Integer
        Dim flag As Boolean

        flag = False
        i = 1
        a(j) = 1

        Do While i &lt;= 8
            Randomize()
            RN = CInt(Int((8 * Rnd()) + 1))

            For j = 1 To i
                If (a(j) = RN) Then
                    flag = True
                    Exit For
                End If
            Next

            If flag = True Then
                flag = False
            Else
                a(i) = RN
                i = i + 1
            End If

        Loop

        btn1.Content = a(1)
        btn2.Content = a(2)
        btn3.Content = a(3)
        btn4.Content = a(4)
        btn5.Content = a(5)
        btn6.Content = a(6)
        btn7.Content = a(7)
        btn8.Content = a(8)
        btn9.Content = &quot;&quot;
    End Sub

    Private Sub btnSH_Click(sender As Object, e As RoutedEventArgs) Handles btnSH.Click
        shuffle()
    End Sub
End Class</pre>

如果你看一下它会很有帮助。

4

1 回答 1

0

编译器可能在将字符串与 btn.Content 进行比较时遇到问题,因为您将 Content 设置为 Integer 类型 (btn1.Content = a(1))

于 2013-07-01T14:26:19.250 回答