CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Ticker (revisited) with Visual Studio 2012 Express

    Hello all!

    I posted once about attempting to code a ticker (scrolling text box) with a background worker on Visual Studio 2012 Express. I learned that it was better to use a timer and did not require a lot of code. After experimenting with this for some time, I figured out how to do it. Part of this post will be to share what I learned (if you want a simple way to do it), and the other is a request for help. I made the ticker for a slot machine program and it works fine as long as the user (player) does not click the "spin" button. If they click the spin button, the entire form freezes while filling in the 5 picture boxes with the images of the cards I am using.

    Once again I am using Visual Studio 2012 Express

    Here is my code:

    Code:
    Public Class Form2
        Public TickerMsg As String = "***** Today's winning bonus is "
        Public NumSpins As Integer
        Public PixNum(5) As Integer
        Public txtCnt As Integer = 0
        Public boxText As String = Nothing
        Public chrchk As String = Nothing
        Public TickerText As String
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            GameStart = True
            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            SETTINGSToolStripMenuItem.Enabled = False
            Label5.Text = Nothing
            Label5.Refresh()
            RectangleShape1.Hide()
            RectangleShape2.Hide()
            RectangleShape3.Hide()
            RectangleShape4.Hide()
            RectangleShape5.Hide()
            NumericUpDown1.Enabled = False
    
            CurrentCreditAmount = CDec(CurrentCreditAmount) - (NumericUpDown1.Value * 5)
            Label8.Text = Format(CurrentCreditAmount, "####.00")
            Label8.Refresh()
    
            Randomize()
    
            NumSpins = CInt(Math.Floor((15 - 7 + 1) * Rnd())) + 7
    
            For x As Integer = 1 To NumSpins
    
                PixNum(1) = CInt(Math.Floor((23 - 0 + 1) * Rnd())) + 0
                PictureBox1.Image = ImageList1.Images.Item(PixNum(1))
    
                PixNum(2) = CInt(Math.Floor((23 - 0 + 1) * Rnd())) + 0
                PictureBox2.Image = ImageList1.Images.Item(PixNum(2))
    
                PixNum(3) = CInt(Math.Floor((23 - 0 + 1) * Rnd())) + 0
                PictureBox3.Image = ImageList1.Images.Item(PixNum(3))
    
                PixNum(4) = CInt(Math.Floor((23 - 0 + 1) * Rnd())) + 0
                PictureBox4.Image = ImageList1.Images.Item(PixNum(4))
    
                PixNum(5) = CInt(Math.Floor((23 - 0 + 1) * Rnd())) + 0
                PictureBox5.Image = ImageList1.Images.Item(PixNum(5))
    
                GroupBox1.Refresh()
                System.Threading.Thread.Sleep(200)
    
            Next
            
        End Sub
    
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
    
            If My.Settings.PayoutLastUpdate = CurDay Then
                PlayerPayout = CDec(My.Settings.MaxDayPayout * 1000)
            ElseIf My.Settings.PayoutLastUpdate <> CurDay Then
                PlayerPayout = PlayerPayout + CDec(My.Settings.MaxDayPayout * 1000)
                My.Settings.PayoutLastUpdate = CurDay
                My.Settings.Save()
            End If
            
        End Sub
    
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            txtCnt += 1
            If txtCnt = 150 Then txtCnt = 1
            chrchk = Mid(TickerText, txtCnt, 1)
    
            If Len(TextBox1.Text) >= 150 Then
                boxText = TextBox1.Text.Remove(0, 1) & chrchk
            Else
                boxText = boxText & chrchk
            End If
    
            TextBox1.Text = boxText
            TextBox1.Refresh()
    
        End Sub
    
    Public Sub Restart_Form()
    
            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            GameStart = False
            Label4.Text = Nothing
            Label5.Text = Nothing
            Label8.Text = Nothing
    
            NumericUpDown1.Value = NumericUpDown1.Minimum
            NumericUpDown1.Enabled = False
    
            PictureBox1.Image = Nothing
            PictureBox2.Image = Nothing
            PictureBox3.Image = Nothing
            PictureBox4.Image = Nothing
            PictureBox5.Image = Nothing
    
            RectangleShape1.Hide()
            RectangleShape2.Hide()
            RectangleShape3.Hide()
            RectangleShape4.Hide()
            RectangleShape5.Hide()
    
            TextBox1.Clear()
            TextBox1.Visible = IIf(My.Settings.ShowTicker = True, True, False)
            TickerText = TickerMsg & Format(PlayerPayout, "$#####.00") & " *****" & Space(104)
            Timer1.Interval = My.Settings.TickerVal * 10
            Timer1.Enabled = IIf(My.Settings.ShowTicker = True, True, False)
    
            EDITToolStripMenuItem.Enabled = False
            NEWToolStripMenuItem.Enabled = True
            SAVEToolStripMenuItem.Enabled = False
            SETTINGSToolStripMenuItem.Enabled = True
    
        End Sub
    Name:  main_screen.jpg
Views: 1001
Size:  29.0 KB

    You will see that 1) I am using an ImageList to hold the pictures of the cards. 2) Upon start of the program, I increase the daily winning amount by 1 thousand dollars and that is displayed in the ticker.

    I know that you will also see the "sleep" line above and most likely attribute my problem to that. I have totally removed that line and still get the exact same issue. Oh, that line is there so that it slows down the changing of the card images to make it look better. The rectangle shapes appear around the picture boxes when there is a win (still working on).

    I will answer any questions you may have so that you can help me determine how to prevent textbox1 and timer1 from freezing with each spin.


    Thank you in advance for your help.
    Last edited by oldGMtireman; July 16th, 2019 at 01:46 PM. Reason: add missing code

  2. #2
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Ticker (revisited) with Visual Studio 2012 Express

    Ok, I get it. Nobody wants to help me anymore. That's ok. Would the administrator PLEASE DELETE MY ENTIRE ACCOUNT!

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Ticker (revisited) with Visual Studio 2012 Express

    I guess the VB guru's are on holiday... Sorry I can't help but I don't use VB. A more active VB forum is on codeguru sister site VB forum. Try posting at http://www.vbforums.com/forumdisplay...sual-Basic-NET

    Good luck with your project.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured