Question Help Needed to make animation from pattern string for displaying Bingo winning patterns

servox

Member
Joined
Jun 30, 2022
Messages
15
Programming Experience
Beginner
Hi all

I'm having a problem creating an animation to show the winning patterns of a bingo game.

this is the string for the pattern, this is a 5x5 pattern. so 25 characters for each pattern. first 5 characters are for line one, next 5 are for line 2 etc

dim strPattern as string = "10000010000010000010000010000100010001000100010000"

so

1000001000001000001000001 ' patten one
0000100010001000100010000 ' pattern two

I thought of using buttons and changing the back colour would be best, but hopefully someone will suggest the best way

I need it to keep looping though the patterns

please see animation.gif the what I'm trying to do and hopefully someone can point me in the right direction

thanks
 

Attachments

  • Pattern1.jpg
    Pattern1.jpg
    9.3 KB · Views: 12
  • Pattern2.jpg
    Pattern2.jpg
    9.3 KB · Views: 11
  • Animation.gif
    Animation.gif
    17.6 KB · Views: 19
There are all sorts of way this could be achieved. Given that Buttons exist for clicking, using them for this alone would be a bit silly. Do you already have Buttons on your form? What you're actually starting from would be a significant factor in the decision of how to implement it, but you've provided no information about that. It looks like you want to actually animate the Bingo card itself, so what is your Bingo card actually made of? Do you even have one yet?
 
There are all sorts of way this could be achieved. Given that Buttons exist for clicking, using them for this alone would be a bit silly. Do you already have Buttons on your form? What you're actually starting from would be a significant factor in the decision of how to implement it, but you've provided no information about that. It looks like you want to actually animate the Bingo card itself, so what is your Bingo card actually made of? Do you even have one yet?

Hi

Thanks for replying

There are no buttons on this form it’s just a presentation screen for displaying numbers called, previous number, ticket colour and showing their bingo ticket etc

The bingo card is made up of a panel and labels which is made visible once you enter the serial number of the ticket and then is displayed and hidden after the check is complete.

This is a new feature which will only show the current pattern that’s in play, and will update to another pattern after it’s been won. so there’s nothing to reuse on the form.

Due to my basic knowledge I only suggested a button, but any ideas or options would be appreciated
 
If you already have Labels, why not just change the colour of those?

I could use these, just have no idea how to make the animation or make the labels change colour to simulate an animation.

Can you help me with this?


The current labels are named

lblR1C1 to lblR1C5
lblR2C1 to lblR2C5
lblR3C1 to lblR3C5
lblR4C1 to lblR4C5
lblR5C1 to lblR5C5
 
Last edited:
I am sure there are better ways to do this, I didn't try to find the niftiest possible solution, but I hope this gets you closer to where you want to get to, this is a .net 8 vb.net Winforms test.

Fill Bingo Card:
   Private Sub btnFillCard_Click(sender As Object, e As EventArgs) Handles btnFillCard.Click

       Dim strPattern(1) As String
       Dim ptrn As String
       Dim rowCellValues() As String
       Dim row As String
       Dim rowCount As Integer = 1
       Dim cellValue As String


       strPattern(0) = "1000001000001000001000001"
       strPattern(1) = "0000100010001000100010000"

       For Each ptrn In strPattern
           ' break the pattern up into 5 character chunks for each row
           rowCellValues = Enumerable.Range(0, ptrn.Length \ 5).Select(Function(x) ptrn.Substring(x * 5, 5)).ToArray()

           ' move through each row and loop each cell
           rowCount = 1
           For Each row In rowCellValues
               ' grab the single character that represents the state of the bingo card
               For cellNum = 1 To 5
                   cellValue = row.Substring(cellNum - 1, 1)
                   ColorCellLabel(cellValue, rowCount, cellNum)
               Next
               rowCount += 1
           Next

           Application.DoEvents()

           ' lets wait a bit before continuing
           System.Threading.Thread.Sleep(250)

       Next
   End Sub

   Private Sub ColorCellLabel(cellValue As String, rowNum As Integer, cellNum As Integer)

       ' change the background of the label
       Dim cellLabel() As Control
       Dim cellColor As Color

       cellLabel = Me.Controls.Find($"R{rowNum}C{cellNum}", True)

       If cellValue = "1" Then
           cellColor = Color.Green
       Else
           cellColor = SystemColors.Control

       End If

       ' the find returns an array, we know there is just one that matches
       cellLabel(0).BackColor = cellColor

   End Sub
 

Attachments

  • Recording 2024-02-07 052045.mp4
    350.5 KB
  • Bingo.zip
    450.5 KB · Views: 3
I am sure there are better ways to do this, I didn't try to find the niftiest possible solution, but I hope this gets you closer to where you want to get to, this is a .net 8 vb.net Winforms test.

Fill Bingo Card:
   Private Sub btnFillCard_Click(sender As Object, e As EventArgs) Handles btnFillCard.Click

       Dim strPattern(1) As String
       Dim ptrn As String
       Dim rowCellValues() As String
       Dim row As String
       Dim rowCount As Integer = 1
       Dim cellValue As String


       strPattern(0) = "1000001000001000001000001"
       strPattern(1) = "0000100010001000100010000"

       For Each ptrn In strPattern
           ' break the pattern up into 5 character chunks for each row
           rowCellValues = Enumerable.Range(0, ptrn.Length \ 5).Select(Function(x) ptrn.Substring(x * 5, 5)).ToArray()

           ' move through each row and loop each cell
           rowCount = 1
           For Each row In rowCellValues
               ' grab the single character that represents the state of the bingo card
               For cellNum = 1 To 5
                   cellValue = row.Substring(cellNum - 1, 1)
                   ColorCellLabel(cellValue, rowCount, cellNum)
               Next
               rowCount += 1
           Next

           Application.DoEvents()

           ' lets wait a bit before continuing
           System.Threading.Thread.Sleep(250)

       Next
   End Sub

   Private Sub ColorCellLabel(cellValue As String, rowNum As Integer, cellNum As Integer)

       ' change the background of the label
       Dim cellLabel() As Control
       Dim cellColor As Color

       cellLabel = Me.Controls.Find($"R{rowNum}C{cellNum}", True)

       If cellValue = "1" Then
           cellColor = Color.Green
       Else
           cellColor = SystemColors.Control

       End If

       ' the find returns an array, we know there is just one that matches
       cellLabel(0).BackColor = cellColor

   End Sub

Thank you so much. This works fine.

I have put the code on a timer and made it loop

Just a couple of questions if you don’t mind

1) Is there a way to make this work on just one strPattern with various pattern from 50 to 250 characters rather than the way you have done it with two strPatterns of 25? My strPattern was seperated to show the pattern more clearly for each pattern

2) my project is in net 4.6 and you tested your coding using net 8. Are there any benefits upgrading to net 8 for me?

Thanks agains for all you help.
 
I have put the code on a timer and made it loop

Well that would be wrong. There would be no loop. Each time the Timer Ticks, you change the pattern. No loop.
 
Well that would be wrong. There would be no loop. Each time the Timer Ticks, you change the pattern. No loop.

Loop probably wasn’t the right word.

I meant set the interval based on the number of patterns so that It seamlessly keep the animation changing at the same duration/pace

Is there any point updating to .net 8 ?
Any benefits?
 
Is there any point updating to .net 8 ?

Probably not, unless you're deploying this application to be used for a significant amount of time into the future. If you were using C# then you could take advantage of some new language features but VB hasn't really changed much and WinForms hasn't really changed at all. .NET Framework 4.8.1 will be supported for some time yet. WinForms also has some minor issues in VS under .NET Core (.NET 5 and later are based on .NET Core) so .NET Framework is a more streamlined experience during development.
 
Thank you so much. This works fine.

I have put the code on a timer and made it loop

Just a couple of questions if you don’t mind

1) Is there a way to make this work on just one strPattern with various pattern from 50 to 250 characters rather than the way you have done it with two strPatterns of 25? My strPattern was seperated to show the pattern more clearly for each pattern

2) my project is in net 4.6 and you tested your coding using net 8. Are there any benefits upgrading to net 8 for me?

Thanks agains for all you help.

Try something like, using the same method for splitting up the rows from the 25 character card
mod to use 1 large string first:
Dim strPattern As String
Dim strPatterns() As String

Dim ptrn As String
Dim rowCellValues() As String
Dim row As String
Dim rowCount As Integer = 1
Dim cellValue As String

strPattern = "50-250 characters"

' chop up the pattern to 25 chr chunks representing each bingo card
strPatterns = Enumerable.Range(0, strPattern.Length \ 25).Select(Function(x) strPattern.Substring(x * 25, 25)).ToArray()

For Each ptrn In strPatterns
   ' break the pattern up into 5 character chunks for each row
   rowCellValues = Enumerable.Range(0, ptrn.Length \ 5).Select(Function(x) ptrn.Substring(x * 5, 5)).ToArray()

   ' move through each row and loop each cell
   rowCount = 1
   For Each row In rowCellValues
       ' grab the single character that represents the state of the bingo card
       For cellNum = 1 To 5
           cellValue = row.Substring(cellNum - 1, 1)
           ColorCellLabel(cellValue, rowCount, cellNum)
       Next
       rowCount += 1
   Next

Next

I just used it as it was the default when I created the little test app.
 
Back
Top