Colored Words or Numbers in VB6

  • Thread starter phion
  • Start date
  • Tags
    Numbers
In summary: Console.WriteLine("Press any key to play again...") Console.ReadKey(True) Else Console.WriteLine("Invalid choice. Please try again.")
  • #1
phion
Gold Member
175
39
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:
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 anyone number (pays 35:1)")
        Console.WriteLine("7. Cash out")
        Console.WriteLine("====================================")
    End Sub

End Module
 
Technology news on Phys.org
  • #2
Console.ForegroundColor = ConsoleColor.Red
 
  • #3
phinds said:
Console.ForegroundColor = ConsoleColor.Red
Wouldn't that just change the entire console color?
 
  • #4
phion said:
Wouldn't that just change the entire console color?
Why don't you try it and see?
 
  • #5
phinds said:
Why don't you try it and see?
Tried it. I managed to change the entire console foreground, but that's not what I am trying to accomplish.
 
  • #6
phion said:
Tried it. I managed to change the entire console foreground, but that's not what I am trying to accomplish.
I don't know what the problem might be. I wrote a sample program and all worked fine.

Capture.JPG
 
  • #7
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.
 
  • #8
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.
 
  • #9
phion said:
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.
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.
 
  • #10
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??
 
  • #11
phion said:
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??
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.
 
  • #12
phion said:
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??
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.
 
  • #13
phinds said:
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.
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.
 
  • #14
Here's the code.

Code:
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 anyone number (pays 35:1)")
        Console.WriteLine("7. Cash out")
        Console.WriteLine("====================================")

    End Sub

End Module
 
  • #15
Code:
                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()
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:
                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
 
  • #16
Mark44 said:
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:
                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
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.
 
  • #17
Mark44 said:
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.
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.
phion said:
I still haven't figured out how to make the 'bank' variable become red if it's negative though, it's always just green.
Code:
If bank < 0 Then
   Console.ForegroundColor = ConsoleColor.Red
Else
   Console.ForegroundColor = ConsoleColor.Green
End If
 
  • #18
TurtleMeister said:
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:
If bank < 0 Then
   Console.ForegroundColor = ConsoleColor.Red
Else
   Console.ForegroundColor = ConsoleColor.Green
End If
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:
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 anyone number (pays 35:1)")
        Console.WriteLine("7. Cash out")
        Console.WriteLine("====================================")

    End Sub
 
  • #19
That's great. If you have the community version then you've got the latest thing.
 

What is VB6?

VB6, or Visual Basic 6, is a programming language and development environment used for building Windows applications. It is an older version of Visual Basic and was released in 1998.

What are Colored Words or Numbers in VB6?

Colored words or numbers in VB6 refer to the use of different colors to make certain words or numbers stand out in the code editor. This can help with readability and organization of the code.

How do I change the color of words or numbers in VB6?

To change the color of words or numbers in VB6, go to the "Tools" menu and select "Options." Then, go to the "Editor Format" tab and choose the color you want to change under "Display Items." You can also select "Custom" to choose a specific color.

Why are colored words or numbers important in VB6?

Colored words or numbers in VB6 can help make the code more visually appealing and easier to read. It can also help with identifying different elements in the code and finding errors.

Can I customize the colors for words or numbers in VB6?

Yes, you can customize the colors for words or numbers in VB6 by following the steps mentioned in the answer to the previous question. This allows you to choose the colors that work best for you and your coding style.

Similar threads

  • Programming and Computer Science
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
3K
Replies
14
Views
6K
Replies
45
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Math Proof Training and Practice
2
Replies
38
Views
6K
  • General Discussion
Replies
2
Views
3K
Replies
3
Views
13K
Back
Top