Click here to Skip to main content
16,006,749 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Dragging graphics images Pin
Christian Graus21-Mar-08 11:28
protectorChristian Graus21-Mar-08 11:28 
GeneralEncrypting the zip file Pin
snagashree21-Mar-08 0:09
snagashree21-Mar-08 0:09 
GeneralRe: Encrypting the zip file Pin
Christian Graus21-Mar-08 11:28
protectorChristian Graus21-Mar-08 11:28 
GeneralRe: Encrypting the zip file Pin
Autodev2-Apr-08 21:46
Autodev2-Apr-08 21:46 
General็How to get path of application if it isn't Windows Form Pin
Krirk20-Mar-08 22:08
Krirk20-Mar-08 22:08 
GeneralRe: ็How to get path of application if it isn't Windows Form Pin
Luc Pattyn21-Mar-08 1:44
sitebuilderLuc Pattyn21-Mar-08 1:44 
GeneralRe: ็How to get path of application if it isn't Windows Form Pin
Krirk21-Mar-08 2:15
Krirk21-Mar-08 2:15 
GeneralHandling button click for equation Pin
Erin020120-Mar-08 10:40
Erin020120-Mar-08 10:40 
Hello,

I am trying to complete a small project in VB, but am having a problem figuring out how to handle a button click within the event of a current button click. The book I am using is not very descriptive in this case and I can't find any other examples with like code. I have most of the project complete, but I am stumped on the extra button click handling part of it. Most projects I have completed just gathered information from textboxes etc, but this is the first that asks for input from another button click and I can not find any examples. I need to have small button click converted into the numbers 1, 2, and 3 respectively so that when the button is clicked, the program will subtract that number from the total and then go back and decide whose turn it is.

The book I am using is: Visual Basic 2005 6th edition by David Schneider

Here is the project requirements:
Write a program that allows the user to challenge the computer to a game of pick-up-sticks. Here is how the game works. The user chooses the number of matchsticks (from 5-50) to place in a pile. Then, the computer chooses who will go first. At each turn, the contestant can remove one, two, or three matchsticks from the pile. The contestant who chooses the last matchstick loses.

The computer should make the user always select from a pile where the number of matchsticks has a remainder of 1 when divided by 4. For instance, if the user initially chooses a number of matchsticks that has a remainder of 1 when divided by 4, then the computer should have the user go first. Otherwise, the computer should go first and remove the proper number of matchsticks. (Note: The remainder when n is divided by 4 is (n Mod 4)) After writing the program, play a few games with the computer and observe that the computer always wins."

My Code So Far:
Public Class frmGame

Private Sub btnRules_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRules.Click
MsgBox("If you would like to play a game of Pick up Sticks, you must first choose a number of sticks from 5-50 to be placed into the pile, then when it is your turn you may select 1, 2, or 3 as the number of sticks to take from the pile. The contestant who chooses the last matchstick loses. Click Begin a New Game to get started.", 0, "Rules")
End Sub

Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim sticks As Double
Dim one As Double
Dim two As Double
Dim three As Double
GetInput(sticks, one, two, three)
DisplayStatus(sticks, one, two, three)
End Sub
' Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
'Dim sticks As Double
' Dim one As Double
' Dim two As Double
' Dim three As Double
'CalculateSticksOne(sticks, one, two, three)
' DisplayStatus(sticks, one, two, three)
' End Sub
Sub GetInput(ByRef sticks As Double, ByRef one As Double, ByRef two As Double, ByRef three As Double)
'calculate which user goes first
sticks = InputBox("Please enter how many sticks the pile should begin with. Choose a number from 5-50.", "Choose number of Sticks")
End Sub
' Sub CalculateSticksOne(ByRef sticks As Double, ByRef one As Double, ByRef two As Double, ByRef three As Double)
' one = 1
' End Sub
Sub DisplayStatus(ByVal sticks As Double, ByVal one As Double, ByVal two As Double, ByVal three As Double)
Dim pile As Double
pile = CalculatePile(sticks, one, two, three)
If pile = MsgBox("It is your turn to choose.", 0, "Pick up Sticks") Then
pile = sticks
txtPile.Text = pile
Else
txtPile.Text = pile
End If
End Sub

Function CalculatePile(ByVal sticks As Double, ByVal one As Double, ByVal two As Double, ByVal three As Double)
Dim status As Double
If sticks Mod 4 = 1 Then
status = MsgBox("It is your turn to choose.", 0, "Pick up Sticks")
Else
status = sticks - 2
End If
Return status
End Function
End Class
-------------
If anyone has any suggestions on how to handle the three small button clicks within the main program click, please let me know! I can not locate this information in the text book and have not been able to find help anywhere else. I think once I can figure out how to code those button clicks, I should be able to be ok as I know I am missing the code where the computer wins, but can code that later. For reference, know that I am expected to utilize sub procedures and functions when appropriate in my programs at this point so I can not eliminate them.

If you would need my project.vb and project.design.vb to look at, please let me know!

Thank you so much in advance!
Erin0201 Smile | :)
GeneralRe: Handling button click for equation Pin
Christian Graus20-Mar-08 11:30
protectorChristian Graus20-Mar-08 11:30 
GeneralAccessing a Custom Cursor In a Resource Folder Pin
bnjneer20-Mar-08 7:09
bnjneer20-Mar-08 7:09 
GeneralRe: Accessing a Custom Cursor In a Resource Folder Pin
A Wong20-Mar-08 7:21
A Wong20-Mar-08 7:21 
GeneralRe: Accessing a Custom Cursor In a Resource Folder Pin
bnjneer22-Mar-08 4:50
bnjneer22-Mar-08 4:50 
Generalerrore in retrev data Pin
asha_s20-Mar-08 6:59
asha_s20-Mar-08 6:59 
GeneralRe: errore in retrev data Pin
Dave Kreskowiak20-Mar-08 7:05
mveDave Kreskowiak20-Mar-08 7:05 
GeneralRe: errore in retrev data Pin
asha_s20-Mar-08 7:29
asha_s20-Mar-08 7:29 
GeneralRe: errore in retrev data Pin
A Wong20-Mar-08 7:38
A Wong20-Mar-08 7:38 
GeneralRe: errore in retrev data Pin
asha_s20-Mar-08 8:22
asha_s20-Mar-08 8:22 
GeneralRe: errore in retrev data Pin
A Wong20-Mar-08 7:09
A Wong20-Mar-08 7:09 
GeneralRe: errore in retrev data Pin
asha_s20-Mar-08 8:25
asha_s20-Mar-08 8:25 
QuestionHow large of file size that can play on media player Pin
abelinze20-Mar-08 4:27
abelinze20-Mar-08 4:27 
AnswerRe: How large of file size that can play on media player Pin
Dave Kreskowiak20-Mar-08 5:30
mveDave Kreskowiak20-Mar-08 5:30 
Questionhelp about Max value?? Pin
outaleb20-Mar-08 4:06
outaleb20-Mar-08 4:06 
AnswerRe: help about Max value?? Pin
Dave Kreskowiak20-Mar-08 5:28
mveDave Kreskowiak20-Mar-08 5:28 
GeneralRe: help about Max value?? Pin
outaleb20-Mar-08 5:34
outaleb20-Mar-08 5:34 
GeneralRe: help about Max value?? Pin
Dave Kreskowiak20-Mar-08 5:58
mveDave Kreskowiak20-Mar-08 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.