Home All Groups Group Topic Archive Search About

Command Button Sequence

Author
11 Oct 2005 5:41 AM
Vance
Using VB.6, When a command button is clicked, the focus can be set to a text
box or a label.  Is it possible to create code that requires a series of
command buttons to be clicked in order to set the focus to a text box or
label?  Example: Click Command Button 1 then Command Button 2 to set focus to
Label 1.
--
Vance

Author
11 Oct 2005 8:10 AM
Jan Hyde
"Vance" <Va***@discussions.microsoft.com>'s wild thoughts
were released on Mon, 10 Oct 2005 22:41:04 -0700 bearing the
following fruit:

>Using VB.6, When a command button is clicked, the focus can be set to a text
>box or a label. 

no, labels can't recieve focus.

>Is it possible to create code that requires a series of
>command buttons to be clicked in order to set the focus to a text box or
>label?  Example: Click Command Button 1 then Command Button 2 to set focus to
>Label 1.

No, because labels can't recieve focus.

Are you trying to do something like this?



Option Explicit

Private pstrSeq As String
Private Sub Command1_Click()
  Record "A"
End Sub

Private Sub Record(ButtonPressed As String)
pstrSeq = pstrSeq & ButtonPressed

If pstrSeq = "AB" Then MsgBox "Success"

If Len(pstrSeq) = 2 Then pstrSeq = ""


End Sub

Private Sub Command2_Click()
  Record "B"
End Sub


Jan Hyde (VB MVP)

--
In a Restaurant window: "Don't stand there and be hungry, come in and get fed up."

(Bill Stebbins)

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Author
11 Oct 2005 8:18 AM
Rick Rothstein [MVP - Visual Basic]
> >Using VB.6, When a command button is clicked, the focus can be
set to a text
> >box or a label.
>
> no, labels can't recieve focus.
>
> >Is it possible to create code that requires a series of
> >command buttons to be clicked in order to set the focus to a
text box or
> >label?  Example: Click Command Button 1 then Command Button 2
to set focus to
Show quoteHide quote
> >Label 1.
>
> No, because labels can't recieve focus.
>
> Are you trying to do something like this?
>
> Option Explicit
>
> Private pstrSeq As String
> Private Sub Command1_Click()
>   Record "A"
> End Sub
>
> Private Sub Record(ButtonPressed As String)
> pstrSeq = pstrSeq & ButtonPressed
>
> If pstrSeq = "AB" Then MsgBox "Success"
>
> If Len(pstrSeq) = 2 Then pstrSeq = ""
>
>
> End Sub
>
> Private Sub Command2_Click()
>   Record "B"
> End Sub

The only problem I see with this approach is... how do you turn it
off? In other words, if the first button is pressed and then other
things are done and then some time later the second button is
pressed, this will rate as a successful sequence of button
presses. Here's a possible alternative that uses a Timer control;
it provides a 1-second window in which the two buttons must be
pressed in the correct sequence.

Private Sub Form_Load()
  Timer1.Interval = 1000
  Timer1.Enabled = False
End Sub

Private Sub Command1_Click()
  Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
  If Timer1.Enabled Then MsgBox "Success"
End Sub

Private Sub Timer1_Timer()
  Timer1.Enabled = False
End Sub

Rick
Author
11 Oct 2005 9:44 AM
Jan Hyde
"Rick Rothstein [MVP - Visual Basic]"
<rickNOSPAMnews@NOSPAMcomcast.net>'s wild thoughts were
released on Tue, 11 Oct 2005 04:18:16 -0400 bearing the
following fruit:

Show quoteHide quote
>> >Using VB.6, When a command button is clicked, the focus can be
>set to a text
>> >box or a label.
>>
>> no, labels can't recieve focus.
>>
>> >Is it possible to create code that requires a series of
>> >command buttons to be clicked in order to set the focus to a
>text box or
>> >label?  Example: Click Command Button 1 then Command Button 2
>to set focus to
>> >Label 1.
>>
>> No, because labels can't recieve focus.
>>
>> Are you trying to do something like this?
>>
>> Option Explicit
>>
>> Private pstrSeq As String
>> Private Sub Command1_Click()
>>   Record "A"
>> End Sub
>>
>> Private Sub Record(ButtonPressed As String)
>> pstrSeq = pstrSeq & ButtonPressed
>>
>> If pstrSeq = "AB" Then MsgBox "Success"
>>
>> If Len(pstrSeq) = 2 Then pstrSeq = ""
>>
>>
>> End Sub
>>
>> Private Sub Command2_Click()
>>   Record "B"
>> End Sub
>
>The only problem I see with this approach is... how do you turn it
>off? In other words, if the first button is pressed and then other
>things are done and then some time later the second button is
>pressed, this will rate as a successful sequence of button
>presses. Here's a possible alternative that uses a Timer control;
>it provides a 1-second window in which the two buttons must be
>pressed in the correct sequence.
>
>Private Sub Form_Load()
>  Timer1.Interval = 1000
>  Timer1.Enabled = False
>End Sub
>
>Private Sub Command1_Click()
>  Timer1.Enabled = True
>End Sub
>
>Private Sub Command2_Click()
>  If Timer1.Enabled Then MsgBox "Success"
>End Sub
>
>Private Sub Timer1_Timer()
>  Timer1.Enabled = False
>End Sub
>
>Rick

Yea, I tried to guess as to why the OP wanted to do this. My
guess was a keypad for entering an PIN.

Perhaps the OP would like to rejoin this dicussion and let
us in on some more details and if either of these solution
has helped?




Jan Hyde (VB MVP)

--
Lysdexia: a peech imspediment we live to learn with. (Ed Hexter)

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Author
11 Oct 2005 3:42 PM
Vance
Thanks for the info so far.  For lack of a better discription, what I am
trying to do is create a form that contains an array of text boxes.  In order
for the end user to input data into a particular text box, a series of two
unique button clicks must occur.  Does this help?
--
Vance


Show quoteHide quote
"Jan Hyde" wrote:

> "Rick Rothstein [MVP - Visual Basic]"
> <rickNOSPAMnews@NOSPAMcomcast.net>'s wild thoughts were
> released on Tue, 11 Oct 2005 04:18:16 -0400 bearing the
> following fruit:
>
> >> >Using VB.6, When a command button is clicked, the focus can be
> >set to a text
> >> >box or a label.
> >>
> >> no, labels can't recieve focus.
> >>
> >> >Is it possible to create code that requires a series of
> >> >command buttons to be clicked in order to set the focus to a
> >text box or
> >> >label?  Example: Click Command Button 1 then Command Button 2
> >to set focus to
> >> >Label 1.
> >>
> >> No, because labels can't recieve focus.
> >>
> >> Are you trying to do something like this?
> >>
> >> Option Explicit
> >>
> >> Private pstrSeq As String
> >> Private Sub Command1_Click()
> >>   Record "A"
> >> End Sub
> >>
> >> Private Sub Record(ButtonPressed As String)
> >> pstrSeq = pstrSeq & ButtonPressed
> >>
> >> If pstrSeq = "AB" Then MsgBox "Success"
> >>
> >> If Len(pstrSeq) = 2 Then pstrSeq = ""
> >>
> >>
> >> End Sub
> >>
> >> Private Sub Command2_Click()
> >>   Record "B"
> >> End Sub
> >
> >The only problem I see with this approach is... how do you turn it
> >off? In other words, if the first button is pressed and then other
> >things are done and then some time later the second button is
> >pressed, this will rate as a successful sequence of button
> >presses. Here's a possible alternative that uses a Timer control;
> >it provides a 1-second window in which the two buttons must be
> >pressed in the correct sequence.
> >
> >Private Sub Form_Load()
> >  Timer1.Interval = 1000
> >  Timer1.Enabled = False
> >End Sub
> >
> >Private Sub Command1_Click()
> >  Timer1.Enabled = True
> >End Sub
> >
> >Private Sub Command2_Click()
> >  If Timer1.Enabled Then MsgBox "Success"
> >End Sub
> >
> >Private Sub Timer1_Timer()
> >  Timer1.Enabled = False
> >End Sub
> >
> >Rick
>
> Yea, I tried to guess as to why the OP wanted to do this. My
> guess was a keypad for entering an PIN.
>
> Perhaps the OP would like to rejoin this dicussion and let
> us in on some more details and if either of these solution
> has helped?
>
>
>
>
> Jan Hyde (VB MVP)
>
> --
> Lysdexia: a peech imspediment we live to learn with. (Ed Hexter)
>
> [Abolish the TV Licence - http://www.tvlicensing.biz/]
>
>
Author
11 Oct 2005 3:49 PM
Rick Rothstein [MVP - Visual Basic]
> Thanks for the info so far.  For lack of a better discription,
what I am
> trying to do is create a form that contains an array of text
boxes.  In order
> for the end user to input data into a particular text box, a
series of two
> unique button clicks must occur.  Does this help?

Instead of you asking if your description helped us, can you tell
us if the code we have posted helped you? I kind of think the code
I posted would be useful for what you are describing, but I am not
completely sure.

Rick
Author
11 Oct 2005 3:51 PM
Someone
> Does this help?

You need to provide more details about what you are trying to do. In the
mean time, check these properties and methods:

Text1(0).SetFocus
Text1(0).Locked = False ' Makes the TextBox read only

You can't do Label1.SetFocus as others said.



Show quoteHide quote
"Vance" <Va***@discussions.microsoft.com> wrote in message
news:13A79469-8E2C-422F-BEA3-EDED2A73FA4E@microsoft.com...
> Thanks for the info so far.  For lack of a better discription, what I am
> trying to do is create a form that contains an array of text boxes.  In
> order
> for the end user to input data into a particular text box, a series of two
> unique button clicks must occur.  Does this help?
> --
> Vance
>
>
> "Jan Hyde" wrote:
>
>> "Rick Rothstein [MVP - Visual Basic]"
>> <rickNOSPAMnews@NOSPAMcomcast.net>'s wild thoughts were
>> released on Tue, 11 Oct 2005 04:18:16 -0400 bearing the
>> following fruit:
>>
>> >> >Using VB.6, When a command button is clicked, the focus can be
>> >set to a text
>> >> >box or a label.
>> >>
>> >> no, labels can't recieve focus.
>> >>
>> >> >Is it possible to create code that requires a series of
>> >> >command buttons to be clicked in order to set the focus to a
>> >text box or
>> >> >label?  Example: Click Command Button 1 then Command Button 2
>> >to set focus to
>> >> >Label 1.
>> >>
>> >> No, because labels can't recieve focus.
>> >>
>> >> Are you trying to do something like this?
>> >>
>> >> Option Explicit
>> >>
>> >> Private pstrSeq As String
>> >> Private Sub Command1_Click()
>> >>   Record "A"
>> >> End Sub
>> >>
>> >> Private Sub Record(ButtonPressed As String)
>> >> pstrSeq = pstrSeq & ButtonPressed
>> >>
>> >> If pstrSeq = "AB" Then MsgBox "Success"
>> >>
>> >> If Len(pstrSeq) = 2 Then pstrSeq = ""
>> >>
>> >>
>> >> End Sub
>> >>
>> >> Private Sub Command2_Click()
>> >>   Record "B"
>> >> End Sub
>> >
>> >The only problem I see with this approach is... how do you turn it
>> >off? In other words, if the first button is pressed and then other
>> >things are done and then some time later the second button is
>> >pressed, this will rate as a successful sequence of button
>> >presses. Here's a possible alternative that uses a Timer control;
>> >it provides a 1-second window in which the two buttons must be
>> >pressed in the correct sequence.
>> >
>> >Private Sub Form_Load()
>> >  Timer1.Interval = 1000
>> >  Timer1.Enabled = False
>> >End Sub
>> >
>> >Private Sub Command1_Click()
>> >  Timer1.Enabled = True
>> >End Sub
>> >
>> >Private Sub Command2_Click()
>> >  If Timer1.Enabled Then MsgBox "Success"
>> >End Sub
>> >
>> >Private Sub Timer1_Timer()
>> >  Timer1.Enabled = False
>> >End Sub
>> >
>> >Rick
>>
>> Yea, I tried to guess as to why the OP wanted to do this. My
>> guess was a keypad for entering an PIN.
>>
>> Perhaps the OP would like to rejoin this dicussion and let
>> us in on some more details and if either of these solution
>> has helped?
>>
>>
>>
>>
>> Jan Hyde (VB MVP)
>>
>> --
>> Lysdexia: a peech imspediment we live to learn with. (Ed Hexter)
>>
>> [Abolish the TV Licence - http://www.tvlicensing.biz/]
>>
>>
Author
11 Oct 2005 5:16 PM
Larry Serflaten
"Vance" <Va***@discussions.microsoft.com> wrote
> Thanks for the info so far.  For lack of a better discription, what I am
> trying to do is create a form that contains an array of text boxes.  In order
> for the end user to input data into a particular text box, a series of two
> unique button clicks must occur.  Does this help?

Just dropping in, the solution seems obvious to me, but in case its not
I thought I would mention it.  Keep a form level variable that tracks
which buttons (of interest) have been pressed and set the textbox
accordingly.  If at some time you need to reset the combination
(eg, turn it off), you simply reset the form level variable.

For an example add 3 buttons and textbox to a new form and
try out the code below....

LFS


Option Explicit
Private Completed As Long

Private Sub Text1_GotFocus()
  If Text1.Locked Then Command1.SetFocus
End Sub

Private Sub Command1_Click()
  Completed = Completed Or 1
  Text1.Locked = (Completed <> 3)
End Sub

Private Sub Command2_Click()
  Completed = Completed Or 2
  Text1.Locked = (Completed <> 3)
End Sub

Private Sub Command3_Click()
  Completed = 0
  Text1.Locked = True
End Sub

Private Sub Form_Load()
  Command1.Caption = "Step A"
  Command2.Caption = "Step B"
  Command3.Caption = "Cancel"
  Text1.Locked = True
  Command1.TabIndex = 0
End Sub
Author
11 Oct 2005 5:30 PM
Jeff Johnson [MVP: VB]
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:OzWZSaozFHA.2132@TK2MSFTNGP15.phx.gbl...

> Just dropping in, the solution seems obvious to me, but in case its not
> I thought I would mention it.  Keep a form level variable that tracks
> which buttons (of interest) have been pressed and set the textbox
> accordingly.  If at some time you need to reset the combination
> (eg, turn it off), you simply reset the form level variable.

And I'll point out that Larry's solution will not work if a specific
SEQUENCE of button presses is needed. However, if it's ANY combination of
the buttons then his solution is fine.
Author
12 Oct 2005 8:26 AM
Jan Hyde
"Vance" <Va***@discussions.microsoft.com>'s wild thoughts
were released on Tue, 11 Oct 2005 08:42:08 -0700 bearing the
following fruit:

>Thanks for the info so far.  For lack of a better discription, what I am
>trying to do is create a form that contains an array of text boxes.  In order
>for the end user to input data into a particular text box, a series of two
>unique button clicks must occur.  Does this help?

It's difficult to imagine what this application does?

I mean, why this approach, why not let the user click on the
textbox they want to enter data into. I'm just interested as
to why you want the unique combination of button clicks.







Jan Hyde (VB MVP)

--
The first scientists who studied fog were mistified.  (Mike Bull)

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Author
12 Oct 2005 3:10 PM
Jeff Johnson [MVP: VB]
Show quote Hide quote
"Jan Hyde" <StellaDrin***@REMOVE.ME.uboot.com> wrote in message
news:32ipk11nlpdcsgrf0b0osjkq5662o0pg1v@4ax.com...

>>Thanks for the info so far.  For lack of a better discription, what I am
>>trying to do is create a form that contains an array of text boxes.  In
>>order
>>for the end user to input data into a particular text box, a series of two
>>unique button clicks must occur.  Does this help?
>
> It's difficult to imagine what this application does?
>
> I mean, why this approach, why not let the user click on the
> textbox they want to enter data into. I'm just interested as
> to why you want the unique combination of button clicks.

Well, it's October. I have to assume school has started in many places....
Author
13 Oct 2005 8:15 AM
Jan Hyde
"Jeff Johnson [MVP: VB]" <i.get@enough.spam>'s wild thoughts
were released on Wed, 12 Oct 2005 11:10:37 -0400 bearing the
following fruit:

Show quoteHide quote
>
>"Jan Hyde" <StellaDrin***@REMOVE.ME.uboot.com> wrote in message
>news:32ipk11nlpdcsgrf0b0osjkq5662o0pg1v@4ax.com...
>
>>>Thanks for the info so far.  For lack of a better discription, what I am
>>>trying to do is create a form that contains an array of text boxes.  In
>>>order
>>>for the end user to input data into a particular text box, a series of two
>>>unique button clicks must occur.  Does this help?
>>
>> It's difficult to imagine what this application does?
>>
>> I mean, why this approach, why not let the user click on the
>> textbox they want to enter data into. I'm just interested as
>> to why you want the unique combination of button clicks.
>
>Well, it's October. I have to assume school has started in many places....
>

Yea, I'm guessing it's a project too, but I love to see the
spec'





Jan Hyde (VB MVP)

--
"I'm no longer invisible" said Tom Insightfully    

(Jan Hyde)

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Author
11 Oct 2005 4:18 PM
Jeff Johnson [MVP: VB]
"Vance" <Va***@discussions.microsoft.com> wrote in message
news:C68FC87F-DC16-4C48-8ACE-2269FC4275CD@microsoft.com...

> Using VB.6, When a command button is clicked, the focus can be set to a
> text
> box or a label.  Is it possible to create code that requires a series of
> command buttons to be clicked in order to set the focus to a text box or
> label?  Example: Click Command Button 1 then Command Button 2 to set focus
> to
> Label 1.

Ultimately you're going to have to KEEP TRACK of which buttons were pressed
and every time a button is pressed you'll have to check the "current
sequence" to see if it's the right one. I recommend using a simple array of
Longs to store this sequence.