Results 1 to 13 of 13

Thread: Need Help VB 2005 buttons. pleeease

  1. #1

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    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

  2. #2

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    Re: Need Help VB 2005 buttons. pleeease

    anyone?

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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?

  4. #4

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private myBoolean As Boolean = True
    2.  
    3. Private Sub MySub()
    4.     If myBoolean Then
    5.         'Do the first thing.
    6.     Else
    7.         'Do the other thing.
    8.     End If
    9.  
    10.     myBoolean = Not myBoolean
    11. End Sub
    or an Integer that you increment:
    VB Code:
    1. Private myInteger As Integer = 0
    2.  
    3. Private Sub MySub()
    4.     If myInteger Mod 2 = 0 Then
    5.         'Do the first thing.
    6.     Else
    7.         'Do the other thing.
    8.     End If
    9.  
    10.     myInteger += 1
    11. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Select Case myInteger Mod 4
    2.     Case 0
    3.         '...
    4.     Case 1
    5.         '...
    6.     Case 2
    7.         '...
    8.     Case 3
    9.         '...
    10. End Select
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    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:
    1. Public Class frmElection
    2.     Dim MsgFlag As Integer = 0
    3.     Private Sub btnVoteKerry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteKerry.Click
    4.         MsgBox("Thank you for voting for the only sensible choice.", MsgBoxStyle.Information)
    5.         Me.Close()
    6.     End Sub
    7.  
    8.     Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click
    9.         Dim result As MsgBoxResult
    10.  
    11.         MsgFlag = MsgFlag + 1
    12.         If MsgFlag = 2 Then
    13.             'This will fire when MsgFlag = 2
    14.             btnVoteGibbo.Width = 20
    15.             btnVoteGibbo.Height = 20
    16.             MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
    17.             MsgFlag = 1
    18.             btnVoteGibbo.Width = 136
    19.             btnVoteGibbo.Height = 41
    20.         Else
    21.             'If MsgFlag is any value other than 2 the message boxes will show
    22.             result = MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?")
    23.             If result = MsgBoxResult.No Then
    24.             Else
    25.                 result = MsgBoxResult.Yes
    26.                 result = MsgBox("Are you really sure?", MsgBoxStyle.YesNo, "Are you sure?")
    27.                 If result = MsgBoxResult.No Then
    28.                 End If
    29.                 'space
    30.                 If result = MsgBoxResult.No Then
    31.                 Else
    32.                     result = MsgBoxResult.Yes
    33.                     result = MsgBox("You can't be serious!", MsgBoxStyle.YesNo, "Are you sure?")
    34.                     If result = MsgBoxResult.No Then
    35.                     End If
    36.                 End If
    37.                 If result = MsgBoxResult.No Then
    38.                 Else
    39.                     result = MsgBoxResult.Yes
    40.                     result = MsgBox("You don't really want to vote for that daywalker!", MsgBoxStyle.YesNo, "Are you sure?")
    41.                     If result = MsgBoxResult.No Then
    42.                     Else
    43.                         MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
    44.                     End If
    45.                 End If
    46.             End If
    47.  
    48.         End If
    49.     End Sub
    50.  
    51. End Class

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Need Help VB 2005 buttons. pleeease

    Try this code:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         If MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?") = MsgBoxResult.Yes Then
    3.             Dim currentSize As Size = Button1.Size
    4.             Dim newSize As Size = New Size(20, 20)
    5.             If currentSize <> newSize Then
    6.                 Button1.Size = newSize
    7.             Else
    8.                 'Put the code to move the button around here
    9.  
    10.             End If
    11.         End If
    12.     End Sub

  9. #9

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    Re: Need Help VB 2005 buttons. pleeease

    doesnt work. it still runs the msgbox code after the resize

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    Re: Need Help VB 2005 buttons. pleeease

    Quote 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

  12. #12
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    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:
    1. Dim myNewInt As Integer =  myInteger Mod 4
    2.  
    3. If myNewInt = 0 Then
    4.      '...
    5. Else If myNewInt = 1 Then
    6.      '...
    7. Else If myNewInt = 2 Then
    8.      '...
    9. Else If myNewInt = 3 Then
    10.      '...
    11. 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

  13. #13

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    Re: Need Help VB 2005 buttons. pleeease

    this works

    VB Code:
    1. Public Class frmElection
    2.     Dim MsgFlag As Integer = 1
    3.     Private Sub btnVoteKerry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteKerry.Click
    4.         MsgBox("Thank you for voting for the only sensible choice.", MsgBoxStyle.Information)
    5.         Me.Close()
    6.     End Sub
    7.  
    8.     Private Sub btnVoteGibbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVoteGibbo.Click
    9.         Dim result As MsgBoxResult
    10.  
    11.  
    12.         Select Case MsgFlag
    13.             Case 1
    14.                 MsgFlag = MsgFlag + 1
    15.                 'If MsgFlag is any value other than 2 the message boxes will show
    16.                 result = MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Are you sure?")
    17.                 If result = MsgBoxResult.No Then
    18.                 Else
    19.                     result = MsgBoxResult.Yes
    20.                     result = MsgBox("Are you really sure?", MsgBoxStyle.YesNo, "Are you sure?")
    21.                     If result = MsgBoxResult.No Then
    22.                     End If
    23.                     'space
    24.                     If result = MsgBoxResult.No Then
    25.                     Else
    26.                         result = MsgBoxResult.Yes
    27.                         result = MsgBox("You can't be serious!", MsgBoxStyle.YesNo, "Are you sure?")
    28.                         If result = MsgBoxResult.No Then
    29.                         End If
    30.                     End If
    31.                     If result = MsgBoxResult.No Then
    32.                     Else
    33.                         result = MsgBoxResult.Yes
    34.                         result = MsgBox("You don't really want to vote for that daywalker!", MsgBoxStyle.YesNo, "Are you sure?")
    35.                         If result = MsgBoxResult.No Then
    36.                         Else
    37.                             MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
    38.                         End If
    39.                     End If
    40.                 End If
    41.             Case 2
    42.                 If MsgFlag = 2 Then
    43.                     'This will fire when MsgFlag = 2
    44.                     btnVoteGibbo.Width = 20
    45.                     btnVoteGibbo.Height = 20
    46.                     MsgBox("A voting error has occured. Please try again", MsgBoxStyle.Critical, "Voting Error")
    47.                     MsgFlag = MsgFlag + 1
    48.                     btnVoteGibbo.Width = 136
    49.                     btnVoteGibbo.Height = 41
    50.                 End If
    51.             Case 3
    52.                 If MsgFlag = 3 Then
    53.                     MsgBox("case3")
    54.                 End If
    55.         End Select
    56.     End Sub
    57. 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
  •  



Click Here to Expand Forum to Full Width