Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

I need to re-populate board after all buttons have been selected.

I've created a Jeopardy style game. What I need to do is re-populate the board of buttons with new questions once all the questions have been answered. When a button has been selected, the text is changed to " ". I've created a function to check if all the button text is blank but it doesn't seem to be calling for the next round of questions. Can anyone see what is wrong?
~TIA
Friend Function roundOver(ByVal sRoundOver As String) As Boolean
        Dim ctrl As Control
        Dim bRoundOver As Boolean = True
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is Button And ctrl.Text = "" = True Then
                bRoundOver = False
                Exit For
            End If
        Next ctrl
    End Function
 
If bRoundOver = True Then
            'hook up array
            arrCol1(0) = btn1200
            arrCol1(1) = btn1400
            arrCol1(2) = btn1600
            arrCol1(3) = btn1800
            arrCol1(4) = btn11000
 
            arrCol2(0) = btn2200
            arrCol2(1) = btn2400
            arrCol2(2) = btn2600
            arrCol2(3) = btn2800
            arrCol2(4) = btn21000
 
            arrCol3(0) = btn3200
            arrCol3(1) = btn3400
            arrCol3(2) = btn3600
            arrCol3(3) = btn3800
            arrCol3(4) = btn31000
 
            arrCol4(0) = btn4200
            arrCol4(1) = btn4400
            arrCol4(2) = btn4600
            arrCol4(3) = btn4800
            arrCol4(4) = btn41000
 
            arrCol5(0) = btn5200
            arrCol5(1) = btn5400
            arrCol5(2) = btn5600
            arrCol5(3) = btn5800
            arrCol5(4) = btn51000
 
            arrCol6(0) = btn6200
            arrCol6(1) = btn6400
            arrCol6(2) = btn6600
            arrCol6(3) = btn6800
            arrCol6(4) = btn61000
 
            dtCategories = oBoard.GetCategories
 
            txtCat1.Text = dtCategories.Rows(0).Item(1)
            txtCat2.Text = dtCategories.Rows(1).Item(1)
            txtCat3.Text = dtCategories.Rows(2).Item(1)
            txtCat4.Text = dtCategories.Rows(3).Item(1)
            txtCat5.Text = dtCategories.Rows(4).Item(1)
            txtCat6.Text = dtCategories.Rows(5).Item(1)
 
            For x = 0 To 5
                oBoard.Used(dtCategories.Rows(x).Item(0))
            Next
            For x = 0 To 4
                arrCol1(x).Text = ("$" & (x + 1) * 200)
                arrCol2(x).Text = ("$" & (x + 1) * 200)
                arrCol3(x).Text = ("$" & (x + 1) * 200)
                arrCol4(x).Text = ("$" & (x + 1) * 200)
                arrCol5(x).Text = ("$" & (x + 1) * 200)
                arrCol6(x).Text = ("$" & (x + 1) * 200)
                My.Computer.Audio.Play("BoardFill.wav")
            Next
            m_Categories = dtCategories
            Me.Show()
        Else
            arrCol1(0) = btn1200
            arrCol1(1) = btn1400
            arrCol1(2) = btn1600
            arrCol1(3) = btn1800
            arrCol1(4) = btn11000
 
            arrCol2(0) = btn2200
            arrCol2(1) = btn2400
            arrCol2(2) = btn2600
            arrCol2(3) = btn2800
            arrCol2(4) = btn21000
 
            arrCol3(0) = btn3200
            arrCol3(1) = btn3400
            arrCol3(2) = btn3600
            arrCol3(3) = btn3800
            arrCol3(4) = btn31000
 
            arrCol4(0) = btn4200
            arrCol4(1) = btn4400
            arrCol4(2) = btn4600
            arrCol4(3) = btn4800
            arrCol4(4) = btn41000
 
            arrCol5(0) = btn5200
            arrCol5(1) = btn5400
            arrCol5(2) = btn5600
            arrCol5(3) = btn5800
            arrCol5(4) = btn51000
 
            arrCol6(0) = btn6200
            arrCol6(1) = btn6400
            arrCol6(2) = btn6600
            arrCol6(3) = btn6800
            arrCol6(4) = btn61000
 
            dtCategories = oBoard.GetCategories
 
            txtCat1.Text = dtCategories.Rows(0).Item(1)
            txtCat2.Text = dtCategories.Rows(1).Item(1)
            txtCat3.Text = dtCategories.Rows(2).Item(1)
            txtCat4.Text = dtCategories.Rows(3).Item(1)
            txtCat5.Text = dtCategories.Rows(4).Item(1)
            txtCat6.Text = dtCategories.Rows(5).Item(1)
 
            For x = 0 To 5
                oBoard.Used(dtCategories.Rows(x).Item(0))
            Next
            For x = 0 To 4
                arrCol1(x).Text = ("$" & (x + 1) * 400)
                arrCol2(x).Text = ("$" & (x + 1) * 400)
                arrCol3(x).Text = ("$" & (x + 1) * 400)
                arrCol4(x).Text = ("$" & (x + 1) * 400)
                arrCol5(x).Text = ("$" & (x + 1) * 400)
                arrCol6(x).Text = ("$" & (x + 1) * 400)
                My.Computer.Audio.Play("BoardFill.wav")
            Next
            m_Categories = dtCategories
            Me.Show()
        End If
    End Sub
 
    Private Sub btnCol1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1200.Click, btn1400.Click, btn1600.Click, btn1800.Click, btn11000.Click
 
        m_sender = Strings.Right(sender.tag, 1)
        icolumn = Strings.Left(sender.tag, 1) - 1
        irow = Strings.Right(sender.tag, 1) - 1
 
        temp = (m_sender * 200)
 
        'hook up array
        Dim frmQ As New frmQuestion
        vwQuestion.RowFilter = "CategoryID = '" & CStr(m_Categories.Rows(icolumn).Item("CategoryID")).Replace("'", "\'") & "'"
        frmQ.Question = vwQuestion.ToTable.Rows(irow).Item(2)
        frmQ.Answer1 = vwQuestion.ToTable.Rows(irow).Item(3)
        frmQ.Answer2 = vwQuestion.ToTable.Rows(irow).Item(4)
        frmQ.Answer3 = vwQuestion.ToTable.Rows(irow).Item(5)
        frmQ.Answer4 = vwQuestion.ToTable.Rows(irow).Item(6)
        frmQ.CorrectAnswer = vwQuestion.ToTable.Rows(irow).Item(7)
 
        Dim btn As Button = DirectCast(sender, Button)
        btn.Text = ""
        btn.Enabled = False
 
        iResult = frmQ.ShowDialog()
        If iResult = 1 Then
            Score = Score + temp
        Else
            Score = Score - temp
        End If
        lblScore.Text = Score
        Call roundOver(bRoundOver)
 
    End Sub

Open in new window

0
98fatboyrider
Asked:
98fatboyrider
  • 3
  • 2
  • 2
1 Solution
 
rlh68Commented:

In your RoundOver method try changing this...

  If TypeOf ctrl Is Button And ctrl.Text = "" = True Then
                bRoundOver = False
                Exit For
            End If

to this...

  If TypeOf ctrl Is Button And ctrl.Text = "" Then
                bRoundOver = False
                Exit For
            End If
0
 
rlh68Commented:

Also you are missing some code, however I am guessing you just mistakenly forgot to post part of your code. Your RoundOver method ends and the next bit of code starts with 'If bRoundOver = True Then' and this code ends with an End Sub.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you find a Button that is not " " then the round isn't over...because you have questions left right?

    Friend Function RoundIsOver() As Boolean
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is Button AndAlso ctrl.Text <> " " Then
                Return False
            End If
        Next
        Return True
    End Function

Call it like this:

    If RoundIsOver() Then
        ...
    End If
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
rlh68Commented:
oops, yes check <> "" as Idle_Mind suggests.
0
 
98fatboyriderAuthor Commented:
Thanks, I think I almost have it now, but how do I check to see if all the buttons are " " after each one is selected?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Huh?...the RoundIsOver() function I gave you will return TRUE if all the buttons are " "...otherwise it returns False.

So just call the RoundIsOver() function in the Click() handler of the buttons or from where ever you execute code after a question is answered.
0
 
98fatboyriderAuthor Commented:
Thank you.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now