Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Colored Words or Numbers in VB6

  1. Oct 7, 2015 #1

    phion

    User Avatar
    Gold Member

    Hi,

    I've written some code in VB6, and I'm trying to figure out how to add color to individual words and numbers.

    The program is a console application Roulette game. What I need to figure out is how to make my money green if positive and red if negative, and color the words "red" and "black" as they appear in the display. Any help is much appreciated. I'm a beginner.

    Code (Text):

    Module Roulette

        Sub Main()
            Dim choice, pick As Integer
            Dim bank, bet, outcome, winnings, payout As Double
            Dim random As New Random

            bank = 100

            Console.WriteLine("Welcome to our casino!")
            Console.WriteLine("We only have Roulette, I hope that's alright.")
            Console.WriteLine("I am starting you out with " & bank.ToString("C") & ", so go nuts!!")
            Console.WriteLine()

            Do
                outcome = random.Next(0, 37)

                menu(bank)
                Console.Write("Please enter your choice: ")
                choice = Console.ReadLine()

                If choice = 7 Then
                    Environment.Exit(7)
                End If

                If choice = 6 Then

                    Do
                        Console.Write("Pick a number: ")
                        pick = Console.ReadLine()
                        Console.Write("Place your bet: ")
                        bet = Console.ReadLine()
                        Console.WriteLine("Press any key to spin the wheel...")
                        Console.ReadKey(True)

                        If pick = outcome And outcome Mod 2 = 0 Then
                            winnings = True
                            payout = 35 * bet
                            Console.WriteLine(outcome & " Red")
                            Console.WriteLine("You win " & payout.ToString("C") & "!")
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()
                        ElseIf pick = outcome And outcome Mod 2 <> 0 Then
                            winnings = True
                            payout = 35 * bet
                            Console.WriteLine("You win " & payout.ToString("C"))
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()
                        ElseIf pick <> outcome And outcome Mod 2 = 0 Then
                            winnings = False
                            payout = bet
                            Console.WriteLine(outcome & " Red")
                            Console.WriteLine("You lose " & payout.ToString("C"))
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()
                        ElseIf pick <> outcome And outcome Mod 2 <> 0 Then
                            winnings = False
                            payout = bet
                            Console.WriteLine(outcome & " Black")
                            Console.WriteLine("You lose " & payout.ToString("C"))
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()
                        End If

                        Exit Do
                    Loop

                End If


                If choice = 1 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 1 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 2 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 2 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome <= 12 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome <= 12 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome > 12 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome > 12 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome > 12 And outcome <= 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome > 12 And outcome <= 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome < 12 Or outcome > 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome < 12 Or outcome > 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome > 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome > 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome < 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Red")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome < 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.WriteLine(outcome & " Black")
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()



                End If

                If winnings = True Then
                    bank += payout
                Else bank -= payout

                End If

            Loop

        End Sub

        Sub menu(ByRef bank As Double)
            Console.WriteLine("Place your bet (" & bank.ToString("C") & ")")
            Console.WriteLine("1. Bet on red (pays 1:1)")
            Console.WriteLine("2. Bet on black (pays 1:1)")
            Console.WriteLine("3. First 12 (pays 2:1)")
            Console.WriteLine("4. Middle 12 (pays 2:1)")
            Console.WriteLine("5. Last 12 (pays 2:1)")
            Console.WriteLine("6. Choose any one number (pays 35:1)")
            Console.WriteLine("7. Cash out")
            Console.WriteLine("====================================")
        End Sub

    End Module
     
     
  2. jcsd
  3. Oct 7, 2015 #2

    phinds

    User Avatar
    Gold Member
    2016 Award

    Console.ForegroundColor = ConsoleColor.Red
     
  4. Oct 7, 2015 #3

    phion

    User Avatar
    Gold Member

    Wouldn't that just change the entire console color?
     
  5. Oct 7, 2015 #4

    phinds

    User Avatar
    Gold Member
    2016 Award

    Why don't you try it and see?
     
  6. Oct 7, 2015 #5

    phion

    User Avatar
    Gold Member

    Tried it. I managed to change the entire console foreground, but that's not what I am trying to accomplish.
     
  7. Oct 7, 2015 #6

    phinds

    User Avatar
    Gold Member
    2016 Award

    I don't know what the problem might be. I wrote a sample program and all worked fine.

    Capture.JPG
     
  8. Oct 7, 2015 #7

    Mark44

    Staff: Mentor

    You could try setting ForegroundColor to red just before you print the text that should be red, and then set ForegroundColor to black afterwards. I haven't tested this, but I believe that you can set this property so that different words are different colors.

    Edit: This is essentially the same as what phinds suggests, but he beat me to the punch.
     
  9. Oct 8, 2015 #8

    phion

    User Avatar
    Gold Member

    I only want one word in a line to be colored, and they need to be specific words, like "Red" and "Black". Also, I need a variable to be green if it's positive, or red if it's negative. I have no idea how to do this.
     
  10. Oct 8, 2015 #9

    Mark44

    Staff: Mentor

    Look at the example that phinds shows. He is coloring a line at a time using WriteLine. You can color a word at a time by using Write.

    The basic idea is:
    1. Change the foreground color to the color you want.
    2. Use Console.Write to display the text
    3. Change the foreground color back to the default color.
    One problem that might be insurmountable is that you are using a very old version of VB that dates from 1998. The example that phinds wrote uses a much more recent version, so I'm not sure what capabilities your version of VB has. It's possible that in your version there is no ability to change the color of text.
     
  11. Oct 8, 2015 #10

    phion

    User Avatar
    Gold Member

    Alright, I figured it out. I wasn't paying attention to the difference between Console.Write and Console.WriteLine. It's working perfectly now!

    I thought VB6 was the latest version of Visual Basic??
     
  12. Oct 8, 2015 #11

    Mark44

    Staff: Mentor

    According to this wiki article, https://en.wikipedia.org/wiki/Visual_Basic, support for VB6 ended completely in 2008. The more current versions are called VB .NET. I believe the latest version is VB .NET 13.
     
  13. Oct 8, 2015 #12

    phinds

    User Avatar
    Gold Member
    2016 Award

    As Mark said, VB6 is long gone. VB.NET is the "replacement". I put "replacement" in quotes because, while they have the same primitive syntax, they are otherwise not terribly similar. VB.NET is considerably more complex because of added power and versatility. Some of the constructs of VB6 just don't exist in VB.NET but there are plenty of new ones. There ARE some things that are much harder to do in VB.NET and I've even found at least one graphics tool that simply cannot be replicated in VB.NET. Also, not all of the constructs work the same between the two, which can be VERY confusing when learning VB.NET. Also, very importantly, the development environment for VB6 is quite primitive compared to the DOT-NET framework.

    If all you are doing is console apps, none of that will make much difference to you.
     
  14. Oct 8, 2015 #13

    phion

    User Avatar
    Gold Member

    Ah, I see, I see. I'll probably switch over to C++ for school soon anyway, but it's good to know the difference!

    The trick here was to change a portion of a sentence to a different color, then change back to the original console colors. I still haven't figured out how to make the 'bank' variable become red if it's negative though, it's always just green.
     
  15. Oct 8, 2015 #14

    phion

    User Avatar
    Gold Member

    Here's the code.

    Code (Text):

    Module Roulette

        Sub Main()
            Dim choice, pick As Integer
            Dim bank, bet, outcome, winnings, payout As Double
            Dim random As New Random

            bank = 100

            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine("Welcome to our casino!")
            Console.WriteLine("We only have Roulette, I hope that's alright.")
            Console.WriteLine("I am starting you out with " & bank.ToString("C") & ", so go nuts!!")
            Console.WriteLine()

            Do

                outcome = random.Next(0, 37)

                menu(bank)

                Console.Write("Please enter your choice: ")
                choice = Console.ReadLine()

                If choice < 1 Or choice > 6 Then

                    Console.WriteLine("Your choice must be between 1 and 6!")
                    Console.Write("Please enter your choice: ")
                    choice = Console.ReadLine()

                End If

                If choice = 7 Then

                    Environment.Exit(7)

                End If

                If choice = 6 Then

                    Do
                        Console.Write("Pick a number: ")
                        pick = Console.ReadLine()
                        Console.Write("Place your bet: ")
                        bet = Console.ReadLine()
                        Console.WriteLine("Press any key to spin the wheel...")
                        Console.ReadKey(True)

                        If pick = outcome And outcome Mod 2 = 0 Then
                            winnings = True
                            payout = 35 * bet
                            Console.Write(outcome)
                            Console.ForegroundColor = ConsoleColor.Red
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine(" Red")
                            Console.ForegroundColor = ConsoleColor.White
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine("You win " & payout.ToString("C") & "!")
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()

                        ElseIf pick = outcome And outcome Mod 2 <> 0 Then
                            winnings = True
                            payout = 35 * bet
                            Console.Write(outcome)
                            Console.ForegroundColor = ConsoleColor.Gray
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine(" Black")
                            Console.ForegroundColor = ConsoleColor.White
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine("You win " & payout.ToString("C"))
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()

                        ElseIf pick <> outcome And outcome Mod 2 = 0 Then
                            winnings = False
                            payout = bet
                            Console.Write(outcome)
                            Console.ForegroundColor = ConsoleColor.Red
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine(" Red")
                            Console.ForegroundColor = ConsoleColor.White
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine("You lose " & payout.ToString("C"))
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()

                        ElseIf pick <> outcome And outcome Mod 2 <> 0 Then
                            winnings = False
                            payout = bet
                            Console.Write(outcome)
                            Console.ForegroundColor = ConsoleColor.Gray
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine(" Black")
                            Console.ForegroundColor = ConsoleColor.White
                            Console.BackgroundColor = ConsoleColor.Black
                            Console.WriteLine("You lose " & payout.ToString("C"))
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()

                        End If

                        Exit Do
                    Loop

                End If

                If choice = 1 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 1 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 2 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 2 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome <= 12 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome <= 12 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome > 12 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 3 And outcome > 12 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome > 12 And outcome <= 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome > 12 And outcome <= 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome < 12 Or outcome > 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 4 And outcome < 12 Or outcome > 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome > 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome > 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = True
                    payout = bet * 2
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You win " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome < 24 And outcome Mod 2 = 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Red
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Red")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                ElseIf choice = 5 And outcome < 24 And outcome Mod 2 <> 0 Then
                    Console.Write("Place your bet: ")
                    bet = Console.ReadLine()
                    Console.WriteLine("Press any key to spin the wheel...")
                    Console.ReadKey(True)
                    winnings = False
                    payout = bet
                    Console.Write(outcome)
                    Console.ForegroundColor = ConsoleColor.Gray
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine(" Black")
                    Console.ForegroundColor = ConsoleColor.White
                    Console.BackgroundColor = ConsoleColor.Black
                    Console.WriteLine("You lose " & payout.ToString("C"))
                    Console.WriteLine("Press any key to play again...")
                    Console.ReadKey(True)
                    Console.Clear()

                End If

                If winnings = True Then
                    bank += payout
                Else : bank -= payout

                End If

            Loop

        End Sub

        Sub menu(ByRef bank As Double)

            Console.Write("Place your bet (")
            Console.ForegroundColor = ConsoleColor.Green
            Console.BackgroundColor = ConsoleColor.Black
            Console.Write(bank.ToString("C"))
            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine(")")
            Console.Write("1. Bet on ")
            Console.ForegroundColor = ConsoleColor.Red
            Console.BackgroundColor = ConsoleColor.Black
            Console.Write("red")
            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine(" (pays 1:1)")
            Console.Write("2. Bet on ")
            Console.ForegroundColor = ConsoleColor.Gray
            Console.BackgroundColor = ConsoleColor.Black
            Console.Write("black")
            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine(" (pays 1:1)")
            Console.WriteLine("3. First 12 (pays 2:1)")
            Console.WriteLine("4. Middle 12 (pays 2:1)")
            Console.WriteLine("5. Last 12 (pays 2:1)")
            Console.WriteLine("6. Choose any one number (pays 35:1)")
            Console.WriteLine("7. Cash out")
            Console.WriteLine("====================================")

        End Sub

    End Module

     
     
  16. Oct 8, 2015 #15

    Mark44

    Staff: Mentor

    Is there some reason why you have these two nearly identical blocks of code? Also, I don't understand why you're fooling with both the foreground and background colors so much. In the first block you print the word "Red" in red. In the second block, you print the word "Black" in gray.
    Wouldn't this work?
    Code ( (Unknown Language)):

                    If pick = outcome Then
                            winnings = True
                            payout = 35 * bet
                            Console.Write(outcome)
                            Console.Write("You win ")
                            Console.ForegroundColor = ConsoleColor.Red
                            Console.Write(payout.ToString("C") & "!")
                            Console.ForegroundColor = ConsoleColor.Black
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()
                    ElseIf pick <> outcome
                            winnings = False
                            payout = bet
                            Console.Write(outcome)
                            Console.Write("You lose ")
                            Console.ForegroundColor = ConsoleColor.Red
                            Console.Write(payout.ToString("C"))
                            Console.ForegroundColor = ConsoleColor.Black
                            Console.WriteLine("Press any key to play again...")
                            Console.ReadKey(True)
                            Console.Clear()
                   Endif
     
     
  17. Oct 8, 2015 #16

    phion

    User Avatar
    Gold Member

    Well, I needed a way to replicate the randomness of choosing the color black, so I decided that if the random variable turned out to be odd than it should be black, and red if even, which is why the modulus of the outcome is not equal to zero, and the foreground is then gray (so you can see the word 'black' against the default console background color). I try not to be too redundant, but it seems necessary with my limited knowledge of this language.
     
  18. Oct 8, 2015 #17
    Actually I think the latest version is code named VB14. It is bundled with Visual Studio 2015 Community along with C# and C++. I tried it out before it was released (the RC version), but after a about a weeks use the IDE crashed and became unusable (It may be more stable by now). So I went back to my VS 2012 express version. I don't know if the express versions are still available, but if they are one of them might be a better choice for someone using an older PC. The 2015 community version IDE was a bit sluggish on my computer.
    Code (Text):

    If bank < 0 Then
       Console.ForegroundColor = ConsoleColor.Red
    Else
       Console.ForegroundColor = ConsoleColor.Green
    End If
     
     
  19. Oct 8, 2015 #18

    phion

    User Avatar
    Gold Member

    That must be what I'm using, since the IDE I have is VS Community 2015. My laptop is pretty new with an SSD and an i7 processor, so I haven't noticed anything really.

    Also, wow, that worked. I had to place it in the sub-routine after the user places their bet.

    Code (Text):

    Sub menu(ByRef bank As Double)

            Console.Write("Place your bet (")
            Console.ForegroundColor = ConsoleColor.Green
            Console.BackgroundColor = ConsoleColor.Black
            If bank < 0 Then
                Console.ForegroundColor = ConsoleColor.Red
            Else
                Console.ForegroundColor = ConsoleColor.Green
            End If
            Console.Write(bank.ToString("C"))
            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine(")")
            Console.Write("1. Bet on ")
            Console.ForegroundColor = ConsoleColor.Red
            Console.BackgroundColor = ConsoleColor.Black
            Console.Write("red")
            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine(" (pays 1:1)")
            Console.Write("2. Bet on ")
            Console.ForegroundColor = ConsoleColor.Gray
            Console.BackgroundColor = ConsoleColor.Black
            Console.Write("black")
            Console.ForegroundColor = ConsoleColor.White
            Console.BackgroundColor = ConsoleColor.Black
            Console.WriteLine(" (pays 1:1)")
            Console.WriteLine("3. First 12 (pays 2:1)")
            Console.WriteLine("4. Middle 12 (pays 2:1)")
            Console.WriteLine("5. Last 12 (pays 2:1)")
            Console.WriteLine("6. Choose any one number (pays 35:1)")
            Console.WriteLine("7. Cash out")
            Console.WriteLine("====================================")

        End Sub
     
     
  20. Oct 8, 2015 #19
    That's great. If you have the community version then you've got the latest thing.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Colored Words or Numbers in VB6
  1. Splitting String-VB6 (Replies: 1)

  2. VB6 Help (Replies: 6)

  3. VB6 Help out of stack (Replies: 2)

Loading...