Results 1 to 4 of 4

Thread: if statement dilemma involving command buttons

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    if statement dilemma involving command buttons

    hi. I have a program which i have made for a term project that is due Tuesday January 23rd :S

    The program is based on the game show "Deal or No Deal". As some of you may be aware the game show consists of 26 cases with different values in each case ranging from 0.01 to 1 million dollars. I am currently working on perfecting my randomization function on another forum ( randomizing array WITHOUT REPEAT) but there is also some other code i need to generate. When the game begins the user must choose which case is going to be theirs. They do this by clicking on the case command button. My dilemma is that my case command buttons all contain code for rest of the game to operate properly. I need to make it so that when the program initially starts all the command buttons operate this code

    VB Code:
    1. Private Sub Case1_Click()
    2. Case1.Top = 8880               ' moves case 1 to bottom of screen  
    3. Case1.Left= 840  
    4. Case1.Enabled=False          ' disable the use of this command button
    5. End Sub

    This code simulates the users taking their selected case as it moves it down to the bottom of the form and disables it until the end of the game when the user checks whats in their case.

    However i also need all of my command buttons to contain this code


    VB Code:
    1. Private Sub Case1_Click()
    2. Formcases.Visible=False   ' closes initial form containing cases
    3. Caseval.Visible=True 'opens form that displays the randomized value of the selected case
    4. Case1.Visible= True 'wipes selected case off so that it cant be selected again
    5. End Sub

    I need this code to be executed ONLY after the user has selected their case as referenced in the earlier code.

    i have tried using if statements but i am not sure what the If condition should be. Input on this problem is much appreciated.

  2. #2
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: if statement dilemma involving command buttons

    Use control arrays so that you wont do hard coding.

    Place a button then copy paste it 26 times. So your code will be like this...


    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2. With Command1
    3.     Select Case Index
    4.         Case 0
    5.             MsgBox "I clicked Briefcase #1"
    6.             .Item(0).Enabled = False
    7.         Case 1
    8.             MsgBox "I clicked Briefcase #2"
    9.             .Item(0).Enabled = False
    10.         Case 2
    11.             MsgBox "I clicked Briefcase #3"
    12.             .Item(0).Enabled = False
    13.     End Select
    14. End With
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18.     For i = Command1.LBound To Command1.UBound
    19.         Command1.Item(i).Caption = i + 1
    20.     Next i
    21. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: if statement dilemma involving command buttons

    good idea im gonna try that out

  4. #4
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: if statement dilemma involving command buttons

    Ooopppsss. I made a mistake...

    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2. With Command1
    3.     Select Case Index
    4.         Case 0
    5.             MsgBox "I clicked Briefcase #1"
    6.             .Item(0).Enabled = False
    7.         Case 1
    8.             MsgBox "I clicked Briefcase #2"
    9.             .Item([B]1[/B]).Enabled = False
    10.         Case 2
    11.             MsgBox "I clicked Briefcase #3"
    12.             .Item([B]2[/B]).Enabled = False
    13.          
    14.         '..... and so on
    15.     End Select
    16. End With
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20.     For i = Command1.LBound To Command1.UBound
    21.         Command1.Item(i).Caption = i + 1
    22.     Next i
    23. End Sub

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