How To Make A Slot Machine In Visual Basic 6.0
The slot machines is a game of chance , many different outcomes will appear when the player press the play button. In this program, we draw an array of nine shapes ,VB will automatically labeled the shapes as shape1(0), shape1(1), shape1(2), shape1(3), shape1(4), shape1(5), shape1(6), shape1(7) and shape1(8) respectively. Arrange the shapes into three rows. Write the code so that only three types of shapes appear randomly. Here we want to show only square, oval and rectangle. The appearance can be altered at runtime using the Shape properties. For example, Shape1(o).Shape=0 means it is a rectangle, Shape1(o).Shape=1 is a square and Shape1(o).Shape=2 is an oval shape. The color of the shapes can be customized using the FillColor property of the shape. For example, Shape1(0).Fillcolor=vbRed will give the shape a red color. The design interface is shown below:
The Design Interface
This wikiHow teaches you how to use Microsoft's Visual Basic 6.0 to create a simple calculator that can add, subtract, multiply, and divide. Keep in mind that Visual Basic 6.0 is no longer used by modern computers, so you'll need to have it installed and running on your computer in order to be able to use it. Since all these functions are implemented as a HTTP client communicating directly with Voicent Gateway, they can be run on any machine that has a connection to the host running the gateway. The Visual Basic interface source code is included at the end of this section.
Randomness can be achieved by using the Rnd function. We also insert a timer to create the animated effect of a slot machine. The time interval is set to 10 so that the shapes change at a fast rate thus creates the illusion of animation. The program also uses a variable x to control the timer so that it can be stopped when x attain a certain value, otherwise the program will loop forever.
The purpose of this program is just to show how different shapes can appear randomly, therefore many advanced features of a slot machine such as the amount of bet are not programmed here. Those features are available in the professional slot machine.
The Code
When you run the program, you will see the following runtime UI:
The Runtime UI
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved Contact Privacy Policy
This sample code shows you how to register your visual basic program on the windows startup registry. First of all, copy and past all below code to a module.
Option Explicit
Public Declare Function RegCloseKey Lib 'advapi32.dll' (ByVal Hkey As Long) As Long
Public Declare Function RegCreateKey Lib 'advapi32.dll' Alias 'RegCreateKeyA' (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegDeleteKey Lib 'advapi32.dll' Alias 'RegDeleteKeyA' (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Public Declare Function RegDeleteValue Lib 'advapi32.dll' Alias 'RegDeleteValueA' (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegOpenKey Lib 'advapi32.dll' Alias 'RegOpenKeyA' (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib 'advapi32.dll' Alias 'RegQueryValueExA' (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Declare Function RegSetValueEx Lib 'advapi32.dll' Alias 'RegSetValueExA' (ByVal Hkey As Long, ByVal lpValueName As String, ByVal reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Const REG_SZ = 1 ' Unicode nul terminated String
Public Const REG_DWORD = 4 ' 32-bit number
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&
Public Sub SaveString(Hkey As Long, strPath As String, strValue As String, strdata As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub
Next, to make the entry in the registry, use code like this (this only really needs to be done once, but could be called in Form_Load each time your app starts):
How To Make A Slot Machine In Visual Basic 6.0 Free
SaveString(HKEY_LOCAL_MACHINE, 'SOFTWAREMicrosoftWindowsCurrentVersionRun', _
App.ExeName, App.Path & ' & App.ExeName & '.exe')
How To Make A Slot Machine In Visual Basic 6.0 Download
Hope this code will make you programming life easy...:D