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:
Private Sub Case1_Click()
Case1.Top = 8880 ' moves case 1 to bottom of screen
Case1.Left= 840
Case1.Enabled=False ' disable the use of this command button
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:
Private Sub Case1_Click()
Formcases.Visible=False ' closes initial form containing cases
Caseval.Visible=True 'opens form that displays the randomized value of the selected case
Case1.Visible= True 'wipes selected case off so that it cant be selected again
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.
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:
Private Sub Command1_Click(Index As Integer)
With Command1
Select Case Index
Case 0
MsgBox "I clicked Briefcase #1"
.Item(0).Enabled = False
Case 1
MsgBox "I clicked Briefcase #2"
.Item(0).Enabled = False
Case 2
MsgBox "I clicked Briefcase #3"
.Item(0).Enabled = False
End Select
End With
End Sub
Private Sub Form_Load()
For i = Command1.LBound To Command1.UBound
Command1.Item(i).Caption = i + 1
Next i
End Sub
Re: if statement dilemma involving command buttons
good idea im gonna try that out
Re: if statement dilemma involving command buttons
Ooopppsss. I made a mistake...
VB Code:
Private Sub Command1_Click(Index As Integer)
With Command1
Select Case Index
Case 0
MsgBox "I clicked Briefcase #1"
.Item(0).Enabled = False
Case 1
MsgBox "I clicked Briefcase #2"
.Item([B]1[/B]).Enabled = False
Case 2
MsgBox "I clicked Briefcase #3"
.Item([B]2[/B]).Enabled = False
'..... and so on
End Select
End With
End Sub
Private Sub Form_Load()
For i = Command1.LBound To Command1.UBound
Command1.Item(i).Caption = i + 1
Next i
End Sub