|
-
Nov 29th, 2006, 04:15 PM
#1
Thread Starter
Banned
Need Help VB 2005 buttons. pleeease
Hi,
im making a voting system program for an assignment which it biased towards one of the candidates, when u click "vote" on the one it doesnt want to win, it displays a few msgboxes. then next time that button is clicked i need the button to resize. ive been thinking for like 3hrs and vb doesnt allow like an OnClick thing or a away to check if the msgboxes part has been done, below is a download link to my project files. someone please check em out im real stuck.
screenshot:

download code:
http://uploadcrap.com/d/dlELECTION.html
code:
Code:
Public Class frmElection
Private Sub btnVoteKerry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteKerry.Click
MsgBox("Thank you for voting for the only sensible choice.", MsgBoxStyle.Information)
Me.Close()
End Sub
Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click
Dim result As MsgBoxResult
Dim ShrinkBtn As Integer
result = MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("Are you really sure?", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
End If
'space
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("You can't be serious!", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
End If
End If
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("You don't really want to vote for that daywalker!", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
Else
MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
End If
End If
End If
End Sub
End Class
-
Nov 29th, 2006, 04:41 PM
#2
Thread Starter
Banned
Re: Need Help VB 2005 buttons. pleeease
anyone?
-
Nov 29th, 2006, 04:53 PM
#3
Re: Need Help VB 2005 buttons. pleeease
1. How many times do you want to confirm when Gibson is voted for?
2. When you you want the button to resize? And by what factor?
-
Nov 29th, 2006, 04:54 PM
#4
Thread Starter
Banned
Re: Need Help VB 2005 buttons. pleeease
Gibson cannot be voted for, the msgbox code should run only once, then on the next click of the button it should resize to say 20, 20. then on the next click after that ill be making the button move around the form so the user cannot click it
-
Nov 29th, 2006, 04:57 PM
#5
Re: Need Help VB 2005 buttons. pleeease
It's not quite clear what you're asking for. Are you saying that when that button is clicked you want two things to happen alternately? The first time the messages, then the second time the button resizes, then the third time the messages, etc.? If so then you just need a variable, declared at class level, that you test each time and then change. It could be a Boolean that you toggle:
VB Code:
Private myBoolean As Boolean = True
Private Sub MySub()
If myBoolean Then
'Do the first thing.
Else
'Do the other thing.
End If
myBoolean = Not myBoolean
End Sub
or an Integer that you increment:
VB Code:
Private myInteger As Integer = 0
Private Sub MySub()
If myInteger Mod 2 = 0 Then
'Do the first thing.
Else
'Do the other thing.
End If
myInteger += 1
End Sub
-
Nov 29th, 2006, 04:59 PM
#6
Re: Need Help VB 2005 buttons. pleeease
OK, just saw those new posts. If you have more than 2 things to do then you'd go with the Integer and use the number of different operations you have instead of 2, e.g.:
VB Code:
Select Case myInteger Mod 4
Case 0
'...
Case 1
'...
Case 2
'...
Case 3
'...
End Select
-
Nov 29th, 2006, 05:09 PM
#7
Thread Starter
Banned
Re: Need Help VB 2005 buttons. pleeease
heres what i have to far
i have to do the following,
1)display the msgboxes
2)resize smaller
3)then after the small button is clicked resize back to normal
4)on the next click move around the form when the user tries to click it
5)the vote buttons should swap places
this code does 1 to 3
VB Code:
Public Class frmElection
Dim MsgFlag As Integer = 0
Private Sub btnVoteKerry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteKerry.Click
MsgBox("Thank you for voting for the only sensible choice.", MsgBoxStyle.Information)
Me.Close()
End Sub
Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click
Dim result As MsgBoxResult
MsgFlag = MsgFlag + 1
If MsgFlag = 2 Then
'This will fire when MsgFlag = 2
btnVoteGibbo.Width = 20
btnVoteGibbo.Height = 20
MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
MsgFlag = 1
btnVoteGibbo.Width = 136
btnVoteGibbo.Height = 41
Else
'If MsgFlag is any value other than 2 the message boxes will show
result = MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("Are you really sure?", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
End If
'space
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("You can't be serious!", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
End If
End If
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("You don't really want to vote for that daywalker!", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
Else
MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
End If
End If
End If
End If
End Sub
End Class
-
Nov 29th, 2006, 05:11 PM
#8
Re: Need Help VB 2005 buttons. pleeease
Try this code:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?") = MsgBoxResult.Yes Then
Dim currentSize As Size = Button1.Size
Dim newSize As Size = New Size(20, 20)
If currentSize <> newSize Then
Button1.Size = newSize
Else
'Put the code to move the button around here
End If
End If
End Sub
-
Nov 29th, 2006, 05:15 PM
#9
Thread Starter
Banned
Re: Need Help VB 2005 buttons. pleeease
doesnt work. it still runs the msgbox code after the resize
-
Nov 29th, 2006, 05:20 PM
#10
Re: Need Help VB 2005 buttons. pleeease
I can't quite see the issue. I've shown you how to accomplish your aim. Use a Select Case statement and use the number of different operations as the second operand to Mod. Have a Case for each number from zero to one less than the number of different operations and put one operation in each Case. Increment the counter after the End Select.
Note that you should put each operation in its own method for clarity, then call those methods from the Cases.
-
Nov 29th, 2006, 05:23 PM
#11
Thread Starter
Banned
Re: Need Help VB 2005 buttons. pleeease
 Originally Posted by jmcilhinney
I can't quite see the issue. I've shown you how to accomplish your aim. Use a Select Case statement and use the number of different operations as the second operand to Mod. Have a Case for each number from zero to one less than the number of different operations and put one operation in each Case. Increment the counter after the End Select.
Note that you should put each operation in its own method for clarity, then call those methods from the Cases.
Sorry i have not yet been taught the "Select Case statement " nor do i understand it
-
Nov 29th, 2006, 05:34 PM
#12
Hyperactive Member
Re: Need Help VB 2005 buttons. pleeease
in lieu of the Select Case statment you could use an If Else If statement like so:
VB Code:
Dim myNewInt As Integer = myInteger Mod 4
If myNewInt = 0 Then
'...
Else If myNewInt = 1 Then
'...
Else If myNewInt = 2 Then
'...
Else If myNewInt = 3 Then
'...
End If
all be it not as clean, but if you don't know Select Case it'll do the job.
If this post helps, please RATE MY POST!
Using Visual Studio 2005 SE
-
Nov 29th, 2006, 05:44 PM
#13
Thread Starter
Banned
Re: Need Help VB 2005 buttons. pleeease
this works
VB Code:
Public Class frmElection
Dim MsgFlag As Integer = 1
Private Sub btnVoteKerry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteKerry.Click
MsgBox("Thank you for voting for the only sensible choice.", MsgBoxStyle.Information)
Me.Close()
End Sub
Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click
Dim result As MsgBoxResult
Select Case MsgFlag
Case 1
MsgFlag = MsgFlag + 1
'If MsgFlag is any value other than 2 the message boxes will show
result = MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("Are you really sure?", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
End If
'space
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("You can't be serious!", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
End If
End If
If result = MsgBoxResult.No Then
Else
result = MsgBoxResult.Yes
result = MsgBox("You don't really want to vote for that daywalker!", MsgBoxStyle.YesNo, "Are you sure?")
If result = MsgBoxResult.No Then
Else
MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
End If
End If
End If
Case 2
If MsgFlag = 2 Then
'This will fire when MsgFlag = 2
btnVoteGibbo.Width = 20
btnVoteGibbo.Height = 20
MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
MsgFlag = MsgFlag + 1
btnVoteGibbo.Width = 136
btnVoteGibbo.Height = 41
End If
Case 3
If MsgFlag = 3 Then
MsgBox("case3")
End If
End Select
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|