Web site translator - 184 CHAPTER 6 MAKING DECISIONS WITH CONDITIONAL
184 CHAPTER 6 MAKING DECISIONS WITH CONDITIONAL LOGIC Tip Take note of the comments embedded throughout this subroutine. By embedding comments into your program code, you help to document it and make it easier to understand. The way this game is played, the player is permitted to select a number between 1 and 100. However, the Slider control has been set up to allow input between 0 and 100. The reason is to provide the Slider control s handle a place to rest at the beginning of the game that does not represent a initial value (for example, to enable the user to start playing without have his first move preselected). Because of this set up, it is necessary to prevent the value of 0 from being displayed when the player moves the Slider control s handle all the way to the left. This is accomplished by adding a If Then block to the Slider control s Mouse Move drag event, as the following shows. ‘Do not update the display of the Slider control’s value when it is zero If sdrControl.Value <> 0 Then ‘Display the Slider control’s value as the player moves its handle edfDisplay.Text = Cstr(sdrControl.Value) End If As you can see, as long as the slider control s value is not equal to zero, it is displayed. The next set of code statements you need to add to the RB Number Guess games is associated with the PushButton control labeled Play (that is, btnPlay). This code, which the following shows, executes each time the player clicks the play button and, thus, belongs in the PushButton control s Action event. ‘A new game is being started Dim r as New Random ‘Instantiate a Random Object intSecretNumber = r.InRange(1,100) ‘Generate a random number sdrControl.Enabled = True ‘Enable the Slider control to allow game play sdrControl.Value = 0 ‘By default the Slider Control’s value is set to zero intNoGuessed = 0 ‘Reset the variable used to track the number of guesses made edfNoOfGuesses.Text = CStr(intNoGuessed) ‘Display the number of guesses made edfDisplay.Text = CStr(sdrControl.Value) ‘Display Slider Control’s value edfAnalysis.Text = “” ‘Clear out the display of the previous game’s status btnPlay.Enabled = False ‘Disable access to the Play button
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.