Need Help. pleeease
Need Help. pleeease
Need Help. pleeease
Need Help. pleeease
Need Help. pleeease
Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease
Need Help. pleeease Need Help. pleeease
Need Help. pleeease
Go Back  Xtreme Visual Basic Talk > > > Need Help. pleeease


Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2006, 02:04 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default Need Help. pleeease [RESOLVED THANKS]


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.

Edit by Moderator: No attachments with binaries in them.


screenshot:
http://img104.imageshack.us/img104/7729/sasdsdcq0.gif

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

Last edited by weebo; 11-29-2006 at 08:13 PM.
Reply With Quote
  #2  
Old 11-29-2006, 02:18 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

You could add a global variable to use as a flag, then when the message boxes are done set the flag to true. In your click event you'll just have to check if the flag is set.
Reply With Quote
  #3  
Old 11-29-2006, 02:20 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

Sorry, im new to programming, been doing this a few weeks, could you tell me the code then i may be able to understand better
Reply With Quote
  #4  
Old 11-29-2006, 02:28 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

Quote:
Originally Posted by weebo
Sorry, im new to programming, been doing this a few weeks, could you tell me the code then i may be able to understand better
A global variable is delcared the same way you declare one withing a function or a sub, except it is declared at the top of your code but still within your class, like so:
Code:
Public Class frmElection Dim MsgFlag as Boolean = False

That would declare a global variable preset to false, so in your btnVoteGibbo click event add an if structure to test if the flag is true or false and execute the desired code. After the code has executed make sure to reset the flag.

If you need to add more conditions, for example if you need the program to do something else after changing the button size, you will need to change to a different type of flag as Boolean can only have one of two values.
Reply With Quote
  #5  
Old 11-29-2006, 02:32 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

do i need the program to do something else after, the button has to move around the form the next time its clicked (i know how to do that) but still i dont really understand how to do something on the button click, why cant vb have something like btnVoteGibbo.Click would be easier :/
EDIT:
Code:
If MsgFlag = True Then btnVoteGibbo.Width = 20 btnVoteGibbo.Height = 20 End If
I did that, but still it just runs it right after the msgboxes close instantly resizing the button. is there a way i could count the button clicks and say if it has been clicked once run the resize code, then if it has been clicked twice run other code like to move the button around the form?

Last edited by weebo; 11-29-2006 at 02:52 PM.
Reply With Quote
  #6  
Old 11-29-2006, 02:35 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

Quote:
Originally Posted by weebo
do i need the program to do something else after, the button has to move around the form the next time its clicked (i know how to do that) but still i dont really understand how to do something on the button click, why cant vb have something like btnVoteGibbo.Click would be easier :/
It does
Code:
Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click

All of your code executes on the click event of your button.
Reply With Quote
  #7  
Old 11-29-2006, 02:40 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

Quote:
Originally Posted by Nayru
It does
Code:
Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click

All of your code executes on the click event of your button.
I know that everything under that rump code is run on click yes, but how do i
Quote:
Originally Posted by Nayru
In your click event you'll just have to check if the flag is set.
Reply With Quote
  #8  
Old 11-29-2006, 02:45 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

Quote:
Originally Posted by weebo
I know that everything under that rump code is run on click yes, but how do i
In the example you asked before of keeping track of how many times a button is clicked, change the global variable to an integer and add one to it every time the button is clicked.

You can then use that number to determine if the button has been pressed previously and if you need to resize it.
Reply With Quote
  #9  
Old 11-29-2006, 02:51 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

ok, here's what i have so far. it resizes on the second click but the msgboxes still run :/
im not sure what i did wrong
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 Dim ShrinkBtn As Integer MsgFlag = MsgFlag + 1 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 If MsgFlag = 2 Then btnVoteGibbo.Width = 20 btnVoteGibbo.Height = 20 End If End Sub End Class
Reply With Quote
  #10  
Old 11-29-2006, 02:54 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

Tehre is nothing telling it not to display the message boxes, all of your code needs to be within the if structure.

Code:
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 MsgFlag = MsgFlag + 1 If MsgFlag = 2 Then 'This will fire when MsgFlag = 2 btnVoteGibbo.Width = 20 btnVoteGibbo.Height = 20 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
Reply With Quote
  #11  
Old 11-29-2006, 02:57 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

ooh i see, ill try it for the next click also
Reply With Quote
  #12  
Old 11-29-2006, 03:00 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

Quote:
Originally Posted by weebo
ooh i see, ill try it for the next click also
You may want to modify you code so that when the message box is resized the flag is reset.

Code:
If MsgFlag = 2 Then 'This will fire when MsgFlag = 2 btnVoteGibbo.Width = 20 btnVoteGibbo.Height = 20 MsgFlag = 1 Else

That way your flag will stay a reasonable number and alternate between the two possible responses.
Reply With Quote
  #13  
Old 11-29-2006, 03:04 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

but there has to be more than 2 things happening, it should in order:
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

code for numbers 1 to 3
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
thats numbers 1 to 3 done.
Reply With Quote
  #14  
Old 11-29-2006, 03:15 PM
jwakeman's Avatar
jwakeman jwakeman is offline
Contributor
 
Join Date: Jul 2005
Posts: 420
Default

It may be time for a select case statement:

Code:
Select Case MsgFlag Case 1 Case 2 Case 3 Me.Top = Me.Top + 150 Me.Left = Me.Left + 150 End Select
Reply With Quote
  #15  
Old 11-29-2006, 03:18 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

Quote:
Originally Posted by jwakeman
It may be time for a select case statement:

Code:
Select Case MsgFlag Case 1 Case 2 Case 3 Me.Top = Me.Top + 150 Me.Left = Me.Left + 150 End Select
I have no idea what that means , but if it moves the button around the form it should do it so that it moves away from the mouse when a click is attempted, :S
Reply With Quote
  #16  
Old 11-29-2006, 03:29 PM
jwakeman's Avatar
jwakeman jwakeman is offline
Contributor
 
Join Date: Jul 2005
Posts: 420
Default

The Select Case Statement could take the place of your growing list of If/Else Statements. So

Code:
If MsgFlag = 1 then 'Do Something elseif MsgFlag =2 then 'Do something else elseif MsgFlag =3 then 'Do another something else else 'Do another other something else endif

Can become

Code:
Select Case MsgFlag Case1 'Do Something Case2 'Do something else Case3 'Do another something else Case Else 'Do another other something else End Select

The
Code:
Me.Top = Me.Top + 150 Me.Left = Me.Left + 150

Will change the position of the form. So you could add this code to the button click event to execute when MsgFlag = 3
Reply With Quote
  #17  
Old 11-29-2006, 03:36 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

ok thanks, ill have a try 2mins
Reply With Quote
  #18  
Old 11-29-2006, 03:42 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

ok so i did this and it seems to work ok

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
Reply With Quote
  #19  
Old 11-29-2006, 04:05 PM
weebo weebo is offline
Centurion
 
Join Date: Dec 2004
Posts: 102
Default

ok thanks for all the help with that, now im having a problem, when the user puts their mouse over the button and tries to click it it should move down the form until it reaches the bottom, they shouldnt be able to click it, i have this so far

Code:
Case 3 tmrElection.Enabled = True If MsgFlag = 3 Then If tmrElection.Enabled = True Then btnVoteGibbo.Top = btnVoteGibbo.Top + 10 End If End If End Select
looks wrong to me and it only makes the button move down when clicked, i need it to happen when its hovering over the top
Reply With Quote
  #20  
Old 11-29-2006, 04:27 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

I have not had much time to look at this but one thing I would do is restructure the IF statements in Case 1 as follows:
Code:
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.Yes Then result = MsgBox("Are you really sure?", MsgBoxStyle.YesNo, "Are you sure?") If result = MsgBoxResult.Yes Then result = MsgBox("You can't be serious!", MsgBoxStyle.YesNo, "Are you sure?") If result = MsgBoxResult.Yes Then result = MsgBox("You don't really want to vote for that daywalker!", MsgBoxStyle.YesNo, "Are you sure?") If result = MsgBoxResult.Yes Then MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error") End If End If End If End If
This makes it much easier to read and see what is going on.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Need Help. pleeease
Need Help. pleeease
Need Help. pleeease Need Help. pleeease
Need Help. pleeease
Need Help. pleeease
Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease Need Help. pleeease
Need Help. pleeease
Need Help. pleeease
 
Need Help. pleeease
Need Help. pleeease
 
-->