Click to See Complete Forum and Search --> : Question No One Can Answere
BlueSony
Jul 5th, 2001, 02:07 PM
I wan't to make a program were if you press all the buttons in any order the screen will close. I can get it to close If I go in order like 1,2,3 or if I end with three. I can't get it to work with just any order. So if you could tell me the code to do this I would be greatfull.
FinnPanther
Jul 5th, 2001, 02:36 PM
Simple: make a boolean for each button in your program.
For example,
Dim blnButton1 As Boolean
Dim blnButton2 As Boolean
Dim blnButton3 As Boolean
Private Sub Button1_Click(blaah blaah...)
blnButton1 = True
Call TestExit
End Sub
Private Sub Button2_Click(blaah blaah...)
blnButton2 = True
Call TestExit
End Sub
Private Sub Button3_Click(blaah blaah...)
blnButton3 = True
Call TestExit
End Sub
Private Sub TestExit()
If blnButton1 _
And blnButton2 _
And blnButton3 _
Then Unload MyForm
End Sub
Like that?
VictorB212
Jul 5th, 2001, 04:51 PM
Can you make all the buttons be part of one control array? If you do that you can make the code a lot smaller.
Option Explicit
Private Sub Command1_Click()
TestExit Command1.TabIndex
End Sub
Private Sub Command2_Click()
TestExit Command2.TabIndex
End Sub
Private Sub Command3_Click()
TestExit Command3.TabIndex
End Sub
Private Sub Command4_Click()
TestExit Command4.TabIndex
End Sub
Private Sub TestExit(Identifier As Long)
Static AllClicked As New Collection
On Error Resume Next
AllClicked.Add Identifier, CStr(Identifier)
If AllClicked.Count = 4 Then Unload Me
End Sub
Change the 4 to however many command buttons you have.
syn_bOy
Jul 6th, 2001, 12:46 PM
You must be a Visual Basic beginner...that thing is the easiest thing to do...come on man!
VictorB212
Jul 6th, 2001, 12:55 PM
Lay off "man," there are always going to be beginners--people worse than you, and there are always going to be experts--people better than you. So cool it. Anyways, you usually don't learn about collections until a little later on, and using a collection is probably the easiest way to do it.
TheSarlacc
Jul 8th, 2001, 09:25 PM
You must be a Visual Basic beginner...that thing is the easiest thing to do...come on man!
leave him alone dickstick! when u began VB, u were a beginner and 100 bucks u asked some questions that u find now are a sinch. so dont be a hipocrit syn_bOy :mad:
Bjwbell
Jul 9th, 2001, 03:06 PM
No need too get angry:cool:
Cheitan
Jul 12th, 2001, 11:36 AM
Dim cmdCloseDim
Private Sub cmdClose_Click(Index As Integer)
For i = 0 To 10
If i = Index Then
cmdCloseDim = cmdCloseDim + 1
cmdClose(Index).Enabled = False
End If
If cmdCloseDim = 11 Then
End
End If
Next i
End Sub
Change the 10 to how many buttons you have, change tthe cmdClose to the name of the buttons; put them all in the same array
It'll disable them as you click on them :D
VictorB212
Jul 12th, 2001, 11:41 AM
Private Sub Command1_Click(Index As Integer)
Static AllClicked As New Collection
On Error Resume Next
AllClicked.Add Index, CStr(Index)
'Command1(Index).Enabled = False
If AllClicked.Count = 10 Then Unload Me
End SubEven shorter, uncomment that line if you want
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.