Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB WPF VB.NET
I am trying to build a 15 number shuffle game in VB.
later on i will have to submit the 15 pieces to a full image.
at the mintime i tries to build it with numbers. it was all working fine until i got this messege:
"Conversion from string "" to type 'Double' is not valid".
i got it line: "If butt2.Content = "" Then"
here is my code:
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 = "1" And btn2.Content = "2" And btn3.Content = "3" And btn4.Content = "4" And btn5.Content = "5" And btn6.Content = "6" And btn7.Content = "7" And btn8.Content = "8" And btn9.Content = "" Then
            MsgBox("הצלחת")
        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 <= 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 = ""
    End Sub
 
    Private Sub btnSH_Click(sender As Object, e As RoutedEventArgs) Handles btnSH.Click
        shuffle()
    End Sub
End Class
it would help a lot if you look at it.
Posted 1-Jul-13 4:15am
Eran89119
Edited 1-Jul-13 4:19am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use double.Parse. This is not your real problem. Your real problem is… the lack of programming. It feels like not a programmer's code, but something created by an inexperience user (non-developer). Fragments of code are just repeated. This is not how programming works. You need to learn how abstraction works. I'm not sure you are ready, but start learning from something, somewhere about the very beginning of programming.
 
—SA
  Permalink  
Comments
Espen Harlinn at 2-Jul-13 10:42am
   
Good points ...
Sergey Alexandrovich Kryukov at 2-Jul-13 11:31am
   
Thank you, Espen.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 Andreas Gieriet 100
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 1 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100