473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Slot Machine Game, need to have frmMachine wait for frmRandom

This is a slot machine game, 2 forms. One is the actual game (frmMachine) and the other is in the background and randomizes the images shown on frmMachine. I need to make frmMachine wait for frmRandom, i tried it with the Sleep API and a Do/Until Loop and neither worked, could you please help me, I have my code below.

frmMachine
Expand|Select|Wrap|Line Numbers
  1. 'Slot Machine, (c) 2006 Peter Browne, GPL Licensed
  2. '
  3. 'Peter Browne
  4. 'Sheridan Corporate Centre
  5. '2155 Leanne Blvd., Ste. 200B
  6. 'Mississauga ON  L5K 2K8
  7. '(905) 616-6099
  8. 'peterrbrowne@hotmail.com
  9. '
  10. '
  11. 'PPPPPPPPPPPPPPPPPPPPPPPPP     PPPPPPPPPPPPPPPPPPPPPPPPP              BBBBBBBBBBBBBBBBBBBB
  12. ' PPPPPPPPPPPPPPPPPPPPPPPPPPP   PPPPPPPPPPPPPPPPPPPPPPPPPP            B                  BB
  13. ' PPPPPPPPP                PP   PPPPPPPPP                PP           B                   BB
  14. ' PPPPPPPPP               PP    PPPPPPPPP               PP            B                    BB
  15. ' PPPPPPPPP              P      PPPPPPPPP               P             B                     BB
  16. ' PPPPPPPPPPPPPPPPPPPPPPP       PPPPPPPPPPPPPPPPPPPPPPPP              B                    BB
  17. ' PPPPPPPPP                     PPPPPPPPPRRR                          B                   BB
  18. ' PPPPPPPPP                     PPPPPPPPP RRR                         B                  BB
  19. ' PPPPPPPPP                     PPPPPPPPP  RRR                        B                 BB
  20. ' PPPPPPPPP                     PPPPPPPPP   RRR                       BBBBBBBBBBBBBBBBBBB
  21. ' PPPPPPPPP                     PPPPPPPPP    RRR                      BBBBBBBBBBBBBBBBBBB
  22. ' PPPPPPPPP                     PPPPPPPPP     RRR                     B                 BB
  23. ' PPPPPPPPP                     PPPPPPPPP      RRR                    B                  BB
  24. ' PPPPPPPPP                     PPPPPPPPP       RRR                   B                   BB
  25. ' PPPPPPPPP                     PPPPPPPPP        RRR                  B                   BB
  26. ' PPPPPPPPP                     PPPPPPPPP         RRR                 B                    BB
  27. ' PPPPPPPPP                     PPPPPPPPP          RRR                B                   BB
  28. ' PPPPPPPPP                     PPPPPPPPP           RRR               B                  BB
  29. 'PPPPPPPPPPP                   PPPPPPPPPPP           RRR              BBBBBBBBBBBBBBBBBBBB
  30. '
  31. '            GNU GENERAL PUBLIC LICENSE
  32. '               Version 2, June 1991
  33. '
  34. ' Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  35. ' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  36. ' Everyone is permitted to copy and distribute verbatim copies
  37. ' of this license document, but changing it is not allowed.
  38. '
  39. '                Preamble
  40. '
  41. '  The licenses for most software are designed to take away your
  42. 'freedom to share and change it.  By contrast, the GNU General Public
  43. 'License is intended to guarantee your freedom to share and change free
  44. 'software--to make sure the software is free for all its users.  This
  45. 'General Public License applies to most of the Free Software
  46. 'Foundation 's software and to any other program whose authors commit to
  47. 'using it.  (Some other Free Software Foundation software is covered by
  48. 'the GNU Lesser General Public License instead.)  You can apply it to
  49. 'your programs, too.
  50. '
  51. '  When we speak of free software, we are referring to freedom, not
  52. 'price.  Our General Public Licenses are designed to make sure that you
  53. 'have the freedom to distribute copies of free software (and charge for
  54. 'this service if you wish), that you receive source code or can get it
  55. 'if you want it, that you can change the software or use pieces of it
  56. 'in new free programs; and that you know you can do these things.
  57. '
  58. '  To protect your rights, we need to make restrictions that forbid
  59. 'anyone to deny you these rights or to ask you to surrender the rights.
  60. 'These restrictions translate to certain responsibilities for you if you
  61. 'distribute copies of the software, or if you modify it.
  62. '
  63. '  For example, if you distribute copies of such a program, whether
  64. 'gratis or for a fee, you must give the recipients all the rights that
  65. 'you have.  You must make sure that they, too, receive or can get the
  66. 'source code.  And you must show them these terms so they know their
  67. 'rights.
  68. '
  69. '  We protect your rights with two steps: (1) copyright the software, and
  70. '(2) offer you this license which gives you legal permission to copy,
  71. 'distribute and/or modify the software.
  72. '
  73. '  Also, for each author's protection and ours, we want to make certain
  74. 'that everyone understands that there is no warranty for this free
  75. 'software.  If the software is modified by someone else and passed on, we
  76. 'want its recipients to know that what they have is not the original, so
  77. 'that any problems introduced by others will not reflect on the original
  78. 'authors ' reputations.
  79. '
  80. '  Finally, any free program is threatened constantly by software
  81. 'patents.  We wish to avoid the danger that redistributors of a free
  82. 'program will individually obtain patent licenses, in effect making the
  83. 'program proprietary.  To prevent this, we have made it clear that any
  84. 'patent must be licensed for everyone's free use or not licensed at all.
  85.  
  86. 'Declares the variables
  87.     Dim Bet As String 'Amount Bet
  88.     Dim Amount As String 'Amount in Account
  89.     Dim RandomImage As Integer 'Random Image
  90.     Dim RandomCount As Integer 'Number of times random image is displayed
  91.     Public One As Integer 'First Image
  92.     Public Two As Integer 'Second Image
  93.     Public Three As Integer 'Third image
  94.  
  95. 'Sleep
  96.     Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  97.  
  98. Private Sub Form_Load()
  99.  
  100.     'Sets the starting amount
  101.     Amount = 250
  102.  
  103.     'Shows the starting amount
  104.     lblAmount.Caption = "You have: $" + Str(Amount)
  105.  
  106.     'Starts the music
  107.     OLE1.DoVerb ' (Play)
  108.  
  109. End Sub
  110.  
  111. Private Sub cmdPull_Click()
  112.  
  113.     'Sets the bet as the input
  114.     Bet = txtBet.Text
  115.  
  116.     'Checks to make sure that the bet is a number
  117.     If Not IsNumeric(Bet) Then
  118.         txtBet.Text = "" 'Clears the input
  119.         MsgBox ("Please enter a dollar amount.") 'Displays the message box
  120.         txtBet.SetFocus 'Sets the focus to be on the input
  121.         Exit Sub 'Ends the program
  122.     End If
  123.  
  124.     'Checks to make sure the bet is positive
  125.     If Bet <= 0 Then
  126.         txtBet.Text = "" 'Clears the input
  127.         MsgBox ("You must enter $1 or more!") 'Displays the message box
  128.         txtBet.SetFocus 'Sets the focus to be on the input
  129.         Exit Sub 'Ends the program
  130.     End If
  131.  
  132.     'Reduces the amount by the bet
  133.     Amount = Amount - Bet
  134.     lblAmount.Caption = "You Have: $" + Str(Amount)
  135.  
  136.     'Checks if the user is trying to bankrupt themselves
  137.     If Amount <= 0 Then
  138.         Amount = Amount + Bet 'Raises the amount to the previous amount
  139.         MsgBox ("You can't bet more then you have!")   'Displays the Message Box
  140.         Exit Sub 'Ends the program
  141.     End If
  142.  
  143.     'Calls frmRandom
  144.     frmRandom.Show
  145.  
  146.     'Pauses for randomization
  147.     Do Until frmRandom.RandomCount = 30
  148.      Loop
  149.  
  150.     'Winner
  151.     If One = Two And Two = Three Then 'Determines if user is a winner
  152.  
  153.         If One = 1 Then 'Sequence for vehicle is One
  154.             Amount = Amount + 25 'Raises the amount by $25
  155.             MsgBox ("You win $25!") 'Displays Message Box
  156.             lblAmount.Caption = "You Have: $" + Str(Amount)
  157.         End If
  158.  
  159.         If One = 2 Then 'Sequence for vehicle is Two
  160.             Amount = Amount + 30 'Raises the amount
  161.             MsgBox ("You Win $30!") 'Displays Message Box
  162.             lblAmount.Caption = "You Have: $" + Str(Amount)
  163.         End If
  164.  
  165.         If One = 3 Then 'Sequence for vehicle is Three
  166.             Amount = Amount + 20 'Raises the amount
  167.             MsgBox ("You Win $20") 'Diplays Message Box
  168.             lblAmount.Caption = "You Have: $" + Str(Amount)
  169.         End If
  170.  
  171.         If One = 4 Then 'Sequence for vehicle is Four
  172.             Amount = Amount - 35 'Lowers the Amount
  173.  
  174.                 If Amount <= 0 Then 'Sequence for bankrupt users
  175.                     Amount = 0
  176.                     MsgBox ("You went bankrupt!  I will now close!")
  177.                     lblAmount.Caption = "You Have: $" + Str(Amount)
  178.                     Unload frmMachine
  179.                     Exit Sub
  180.                 End If
  181.  
  182.             MsgBox ("You Lost $35!")
  183.             lblAmount.Caption = "You Have: $" + Str(Amount)
  184.         End If
  185.  
  186.     Else 'If user did not win
  187.         MsgBox ("You did not win!")
  188.         MsgBox ("Please try again!")
  189.  
  190.     End If
  191. End Sub
  192.  
  193. Private Sub cmdDone_Click()
  194.  
  195.     'Closes the program
  196.     Unload frmMachine
  197.  
  198. End Sub
  199.  
Nov 24 '06 #1
1 5647
frmRandom
Expand|Select|Wrap|Line Numbers
  1. 'Slot Machine, (c) 2006 Peter Browne, GPL Licensed
  2. '
  3. 'Peter Browne
  4. 'Sheridan Corporate Centre
  5. '2155 Leanne Blvd., Ste. 200B
  6. 'Mississauga ON  L5K 2K8
  7. '(905) 616-6099
  8. 'peterrbrowne@hotmail.com
  9. '
  10. '
  11. 'PPPPPPPPPPPPPPPPPPPPPPPPP     PPPPPPPPPPPPPPPPPPPPPPPPP              BBBBBBBBBBBBBBBBBBBB
  12. ' PPPPPPPPPPPPPPPPPPPPPPPPPPP   PPPPPPPPPPPPPPPPPPPPPPPPPP            B                  BB
  13. ' PPPPPPPPP                PP   PPPPPPPPP                PP           B                   BB
  14. ' PPPPPPPPP               PP    PPPPPPPPP               PP            B                    BB
  15. ' PPPPPPPPP              P      PPPPPPPPP               P             B                     BB
  16. ' PPPPPPPPPPPPPPPPPPPPPPP       PPPPPPPPPPPPPPPPPPPPPPPP              B                    BB
  17. ' PPPPPPPPP                     PPPPPPPPPRRR                          B                   BB
  18. ' PPPPPPPPP                     PPPPPPPPP RRR                         B                  BB
  19. ' PPPPPPPPP                     PPPPPPPPP  RRR                        B                 BB
  20. ' PPPPPPPPP                     PPPPPPPPP   RRR                       BBBBBBBBBBBBBBBBBBB
  21. ' PPPPPPPPP                     PPPPPPPPP    RRR                      BBBBBBBBBBBBBBBBBBB
  22. ' PPPPPPPPP                     PPPPPPPPP     RRR                     B                 BB
  23. ' PPPPPPPPP                     PPPPPPPPP      RRR                    B                  BB
  24. ' PPPPPPPPP                     PPPPPPPPP       RRR                   B                   BB
  25. ' PPPPPPPPP                     PPPPPPPPP        RRR                  B                   BB
  26. ' PPPPPPPPP                     PPPPPPPPP         RRR                 B                    BB
  27. ' PPPPPPPPP                     PPPPPPPPP          RRR                B                   BB
  28. ' PPPPPPPPP                     PPPPPPPPP           RRR               B                  BB
  29. 'PPPPPPPPPPP                   PPPPPPPPPPP           RRR              BBBBBBBBBBBBBBBBBBBB
  30. '
  31. '            GNU GENERAL PUBLIC LICENSE
  32. '               Version 2, June 1991
  33. '
  34. ' Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  35. ' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  36. ' Everyone is permitted to copy and distribute verbatim copies
  37. ' of this license document, but changing it is not allowed.
  38. '
  39. '                Preamble
  40. '
  41. '  The licenses for most software are designed to take away your
  42. 'freedom to share and change it.  By contrast, the GNU General Public
  43. 'License is intended to guarantee your freedom to share and change free
  44. 'software--to make sure the software is free for all its users.  This
  45. 'General Public License applies to most of the Free Software
  46. 'Foundation 's software and to any other program whose authors commit to
  47. 'using it.  (Some other Free Software Foundation software is covered by
  48. 'the GNU Lesser General Public License instead.)  You can apply it to
  49. 'your programs, too.
  50. '
  51. '  When we speak of free software, we are referring to freedom, not
  52. 'price.  Our General Public Licenses are designed to make sure that you
  53. 'have the freedom to distribute copies of free software (and charge for
  54. 'this service if you wish), that you receive source code or can get it
  55. 'if you want it, that you can change the software or use pieces of it
  56. 'in new free programs; and that you know you can do these things.
  57. '
  58. '  To protect your rights, we need to make restrictions that forbid
  59. 'anyone to deny you these rights or to ask you to surrender the rights.
  60. 'These restrictions translate to certain responsibilities for you if you
  61. 'distribute copies of the software, or if you modify it.
  62. '
  63. '  For example, if you distribute copies of such a program, whether
  64. 'gratis or for a fee, you must give the recipients all the rights that
  65. 'you have.  You must make sure that they, too, receive or can get the
  66. 'source code.  And you must show them these terms so they know their
  67. 'rights.
  68. '
  69. '  We protect your rights with two steps: (1) copyright the software, and
  70. '(2) offer you this license which gives you legal permission to copy,
  71. 'distribute and/or modify the software.
  72. '
  73. '  Also, for each author's protection and ours, we want to make certain
  74. 'that everyone understands that there is no warranty for this free
  75. 'software.  If the software is modified by someone else and passed on, we
  76. 'want its recipients to know that what they have is not the original, so
  77. 'that any problems introduced by others will not reflect on the original
  78. 'authors ' reputations.
  79. '
  80. '  Finally, any free program is threatened constantly by software
  81. 'patents.  We wish to avoid the danger that redistributors of a free
  82. 'program will individually obtain patent licenses, in effect making the
  83. 'program proprietary.  To prevent this, we have made it clear that any
  84. 'patent must be licensed for everyone's free use or not licensed at all.
  85. '
  86.     Dim RandomImage As Integer 'Random Image
  87.     Public RandomCount As Integer 'Number of times random image is displayed
  88.     Public One As Integer 'First Image
  89.     Public Two As Integer 'Second Image
  90.     Public Three As Integer 'Third image
  91.  
  92. Private Sub tmrOne_Timer()
  93.  
  94.     'Code to randomize imgOne and display the images
  95.     'RandomCount = 0 'Resets the RandomCount
  96.     'Do Until RandomCount = 10 'Start the Loop
  97.         RandomCount = RandomCount + 1 'Add one to RandomCount
  98.         RandomImage = Int(4 * Rnd + 1) 'Selects a random image
  99.         If RandomImage = 1 Then 'If the random image is 1 then...
  100.             One = 1
  101.             frmMachine.imgOne.Picture = LoadPicture("G:\crossblade.bmp")
  102.         End If
  103.         If RandomImage = 2 Then 'If image 2 is selected
  104.             One = 2
  105.             frmMachine.imgOne.Picture = LoadPicture("G:\crosstown.bmp")
  106.         End If
  107.         If RandomImage = 3 Then 'If the random image is 1 then...
  108.             One = 3
  109.             frmMachine.imgOne.Picture = LoadPicture("G:\hello yellow.bmp")
  110.         End If
  111.         If RandomImage = 4 Then 'If the random image is 1 then...
  112.             One = 4
  113.             frmMachine.imgOne.Picture = LoadPicture("G:\h1.bmp")
  114.         End If
  115.     'Loop
  116.  
  117.     'Code to randomize imgTwo and display the images
  118.     'RandomCount = 0 'Resets the RandomCount
  119.     'Do Until RandomCount = 20 'Start the Loop
  120.         RandomCount = RandomCount + 1 'Add one to RandomCount
  121.         RandomImage = Int(4 * Rnd + 1) 'Selects a random image
  122.         If RandomImage = 1 Then 'If the random image is 1 then...
  123.             Two = 1
  124.             frmMachine.imgTwo.Picture = LoadPicture("G:\crossblade.bmp")
  125.         End If
  126.         If RandomImage = 2 Then 'If image 2 is selected
  127.             Two = 2
  128.             frmMachine.imgTwo.Picture = LoadPicture("G:\crosstown.bmp")
  129.         End If
  130.         If RandomImage = 3 Then 'If the random image is 1 then...
  131.             Two = 3
  132.             frmMachine.imgOne.Picture = LoadPicture("G:\hello yellow.bmp")
  133.         End If
  134.         If RandomImage = 4 Then 'If the random image is 1 then...
  135.             Two = 4
  136.             frmMachine.imgOne.Picture = LoadPicture("G:\h1.bmp")
  137.         End If
  138.     'Loop
  139.  
  140.     'Code to randomize imgThree and display the images
  141.     'RandomCount = 0 'Resets the RandomCount
  142.     'Do Until RandomCount = 30 'Start the Loop
  143.         RandomCount = RandomCount + 1 'Add one to RandomCount
  144.         RandomImage = Int(4 * Rnd + 1) 'Selects a random image
  145.         If RandomImage = 1 Then 'If the random image is 1 then...
  146.             Three = 1
  147.             frmMachine.imgThree.Picture = LoadPicture("G:\crossblade.bmp")
  148.         End If
  149.         If RandomImage = 2 Then 'If image 2 is selected
  150.             Three = 2
  151.             frmMachine.imgThree.Picture = LoadPicture("G:\crosstown.bmp")
  152.         End If
  153.         If RandomImage = 3 Then 'If the random image is 1 then...
  154.             Three = 3
  155.             frmMachine.imgOne.Picture = LoadPicture("G:\hello yellow.bmp")
  156.         End If
  157.         If RandomImage = 4 Then 'If the random image is 1 then...
  158.             Three = 4
  159.             frmMachine.imgOne.Picture = LoadPicture("G:\h1.bmp")
  160.         End If
  161.     'Loop
  162.  
  163.     If RandomCount = 30 Then
  164.  
  165.         'Transfers values to frmMachine
  166.         frmMachine.One = One
  167.         frmMachine.Two = Two
  168.         frmMachine.Three = Three
  169.  
  170.         Unload frmRandom
  171.  
  172.     End If
  173.  
  174. End Sub
  175.  
Nov 24 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: 1kHz | last post by:
Hi all.. I'm new with this Ajax thingy and have done some experimenting. I did some codes according to examples from http://www.webpasties.com/xmlHttpRequest/ and...
15
by: carr4895 | last post by:
Hello. I was wondering if someone could help me too with a login form. Upon startup, I have to display a password screen and it should accept a user name and password. User name can be anything...
1
by: MingChih Tsai | last post by:
Hi there, Are there any slot machine c# sample codes for reference ? Thanks !! Best regards, Paul
1
by: raishi | last post by:
I am trying to figure out how to make a simple slot machine program in VBScript that starts by prompting and collecting the desired number of slot machine spins to simulate simulates the spins:...
0
by: Oriane | last post by:
Hi there, I read that the .NET 3.5 Compact .net framework is in Beta. What would you suggest to build from now on a new .NET client/server application running on several Windows CE and a W2k3...
3
by: noob2008 | last post by:
this code works but theres a problem wif it. wen it generates for 4 players, it has repeated values i.e 2 of diamond appear twice. how do i avoid this? and i hav no idea how to program the...
0
by: Mike | last post by:
I am a novice writing a simple program in Visual C++ Express and am having an issue. I basically have several picture boxes of the same size on top of each other with only one visible at a time. ...
7
by: dirtysouth6975 | last post by:
I need some help. I am getting an error of: local function definitions are illegal. What does this mean? Can anybody help me out a little? Thank you. //Specification: This program simulates a three...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.