| Author |
Stupid Questions from a Newbie
|
|
| Bruce Hildebrand 2005-03-24, 3:55 am |
| 1) when i first run the app, position the cursor to the first text box.
2) have the three text boxes accept the enter key and proceed to the next
text box.
What is the best way to accomplish this?
Thanks in Advance.
| |
| James Gockel 2005-03-24, 3:55 am |
| I can't tell you the code exactly, because i dont have VB in front of me.
But here's what to look for.
There is a sub for when the form loads. Call something like
text1.focus = true '( i may be wrong)
Then there is a sub for each time a character is entered into the text
box... you can do it based on Length of the string... or on the keycode
vb.enter (I think that may still work, it used to in VB5 i think.)
If key = vb.enter then
text2.focus = true '(or whatever the call is)
end if
Give that a thought.
-James
"Bruce Hildebrand" <wizard@wizardnco.com> wrote in message
news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl...
> 1) when i first run the app, position the cursor to the first text box.
>
> 2) have the three text boxes accept the enter key and proceed to the next
> text box.
>
> What is the best way to accomplish this?
>
> Thanks in Advance.
>
>
| |
| NickHK 2005-03-24, 3:55 am |
| Bruce,
1. Look into the TabIndex property of the control (and TabStop while you're
at it).
2. Would using the TAB key be good enough ? If so, see #1 above. If not post
back.
NickHK
"Bruce Hildebrand" <wizard@wizardnco.com> wrote in message
news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl...
> 1) when i first run the app, position the cursor to the first text box.
>
> 2) have the three text boxes accept the enter key and proceed to the next
> text box.
>
> What is the best way to accomplish this?
>
> Thanks in Advance.
>
>
| |
| Bruce Hildebrand 2005-03-24, 3:55 am |
| Forgot to mention VB6 not VB.NET
"James Gockel" <flibbertigibbet007_at_hotmail_dot_com> wrote in message
news:OIwPThDMFHA.1392@TK2MSFTNGP10.phx.gbl...
>I can't tell you the code exactly, because i dont have VB in front of me.
> But here's what to look for.
> There is a sub for when the form loads. Call something like
> text1.focus = true '( i may be wrong)
> Then there is a sub for each time a character is entered into the text
> box... you can do it based on Length of the string... or on the keycode
> vb.enter (I think that may still work, it used to in VB5 i think.)
>
> If key = vb.enter then
> text2.focus = true '(or whatever the call is)
> end if
>
> Give that a thought.
> -James
>
>
> "Bruce Hildebrand" <wizard@wizardnco.com> wrote in message
> news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl...
>
>
| |
| Bruce Hildebrand 2005-03-24, 3:55 am |
| Unfortunately, the users of this program want the enter key to function
pretty much like the tab key. Sort of like entering values into Excel.
The TAB key works already, was just hoping there was an easy way to control
the input.
Also, on first use, position the cursor for entry into textbox 1
"NickHK" <TungCheWah@Invalid.com> wrote in message
news:%23hDUxkDMFHA.3988@tk2msftngp13.phx.gbl...
> Bruce,
> 1. Look into the TabIndex property of the control (and TabStop while
> you're
> at it).
>
> 2. Would using the TAB key be good enough ? If so, see #1 above. If not
> post
> back.
>
> NickHK
>
>
> "Bruce Hildebrand" <wizard@wizardnco.com> wrote in message
> news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl...
>
>
| |
| James Gockel 2005-03-24, 8:55 am |
| Eh forgot to mention... last VB I used is vb5...
So I was just mentioning look for somthing like that.
-James
"Bruce Hildebrand" <NOSPAMFORwizard@wizardnco.com> wrote in message
news:ueGLykDMFHA.2464@TK2MSFTNGP10.phx.gbl...
> Forgot to mention VB6 not VB.NET
>
>
> "James Gockel" <flibbertigibbet007_at_hotmail_dot_com> wrote in message
> news:OIwPThDMFHA.1392@TK2MSFTNGP10.phx.gbl...
>
>
| |
| James Gockel 2005-03-24, 8:55 am |
| Anyway...
Set the tab index to 0 on the first textbox
and on KeyDown
State
IF Keycode = vbkeycodereturn then
Text2.setfocus
end if
and so on
-James
"Bruce Hildebrand" <NOSPAMFORwizard@wizardnco.com> wrote in message
news:ueGLykDMFHA.2464@TK2MSFTNGP10.phx.gbl...
> Forgot to mention VB6 not VB.NET
>
>
> "James Gockel" <flibbertigibbet007_at_hotmail_dot_com> wrote in message
> news:OIwPThDMFHA.1392@TK2MSFTNGP10.phx.gbl...
>
>
| |
| J French 2005-03-24, 8:55 am |
| On Wed, 23 Mar 2005 22:29:58 -0800, "Bruce Hildebrand"
<NOSPAMFORwizard@wizardnco.com> wrote:
>Unfortunately, the users of this program want the enter key to function
>pretty much like the tab key. Sort of like entering values into Excel.
>
>The TAB key works already, was just hoping there was an easy way to control
>the input.
>
>Also, on first use, position the cursor for entry into textbox 1
Here is a /very/ crude example
- mainly designed to get you to use Control Arrays
Note: I don't like using SendKeys, and if you are using Control Arrays
then you can control which Textbox is 'current'
- and force focus onto it explicitly
Option Explicit
Private Sub Form_Activate()
Static Flag As Boolean
If Flag = False Then
Flag = True
Text2.SetFocus ' <--- Note Text2
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0 ' Burn off key
SendKeys "{TAB}"
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
SendKeys "{TAB}"
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
SendKeys "{TAB}"
End If
End Sub
| |
| Tim Baur 2005-03-24, 3:55 pm |
| "Bruce Hildebrand" <wizard@wizardnco.com> wrote in
news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl:
> 1) when i first run the app, position the cursor to the first text
> box.
>
> 2) have the three text boxes accept the enter key and proceed to the
> next text box.
>
> What is the best way to accomplish this?
>
> Thanks in Advance.
>
>
You can try the following. This example uses four non-array text boxes.
The order is set by building a collection in Form_Load. To change the
focus order, rearrange the lines. Hitting return in the last box will
put you back into the first.
It can be modified to work with any control. Just declare everything As
Object instead of TextBox
* * * * * * * *
Private colTextBoxes As Collection
Private Sub Form_Load()
Set colTextBoxes = New Collection
colTextBoxes.Add Text1
colTextBoxes.Add Text2
colTextBoxes.Add Text3
colTextBoxes.Add Text4
End Sub
Private Sub SwitchBox(oControl As TextBox)
Dim oBox As TextBox
Dim bFound As Boolean
For Each oBox In colTextBoxes
If bFound Then Exit For
bFound = oBox Is oControl
Next oBox
If oBox Is Nothing Then
colTextBoxes(1).SetFocus
Else
oBox.SetFocus
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SwitchBox Text1
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SwitchBox Text2
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SwitchBox Text3
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SwitchBox Text4
End Sub
| |
| Randy Birch 2005-03-24, 8:55 pm |
| 1) set the tabstop property true, and set that control's tabindex to 0. If
you try to set focus to the control in the load event, you'll throw an error
as the form is not on-screen when the setfocus call is made.
2) The usual suggestion is to use SendKeys, but that has problems. The
workaround is to simulate SendKeys using the keybd_event API ... see
http://vbnet.mvps.org/code/screen/k...nt_sendkeys.htm
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------
"Bruce Hildebrand" <wizard@wizardnco.com> wrote in message
news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl...
: 1) when i first run the app, position the cursor to the first text box.
:
: 2) have the three text boxes accept the enter key and proceed to the next
: text box.
:
: What is the best way to accomplish this?
:
: Thanks in Advance.
:
:
| |
| Larry Serflaten 2005-03-25, 3:55 am |
|
"Bruce Hildebrand" <wizard@wizardnco.com> wrote
> 1) when i first run the app, position the cursor to the first text box.
Use the TabIndex property to set the tab order, where the 0th item
in the order will be given the focus on first load..
>
> 2) have the three text boxes accept the enter key and proceed to the next
> text box.
>
> What is the best way to accomplish this?
Use a control array to provide an index you can use to reference the next
control.
Option Explicit
Private Focus(0 To 2) As TextBox
Private Sub Form_Load()
Set Focus(0) = txtInput(1)
Set Focus(1) = txtInput(2)
Set Focus(2) = txtInput(0)
End Sub
Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Focus(Index).SetFocus
End If
End Sub
HTH
LFS
| |
| Kevan Hughes 2005-03-28, 8:55 pm |
| Guys,
I have used the keyascii code.. How can i get rid of the annoying BEEP when
ENTER key is pressed ?
Thanks
"Larry Serflaten" skrev:
>
> "Bruce Hildebrand" <wizard@wizardnco.com> wrote
>
> Use the TabIndex property to set the tab order, where the 0th item
> in the order will be given the focus on first load..
>
>
>
> Use a control array to provide an index you can use to reference the next
> control.
>
> Option Explicit
> Private Focus(0 To 2) As TextBox
>
> Private Sub Form_Load()
> Set Focus(0) = txtInput(1)
> Set Focus(1) = txtInput(2)
> Set Focus(2) = txtInput(0)
> End Sub
>
> Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
> If KeyAscii = vbKeyReturn Then
> KeyAscii = 0
> Focus(Index).SetFocus
> End If
> End Sub
>
> HTH
> LFS
>
>
>
| |
| Ken Halter 2005-03-28, 8:55 pm |
| "Kevan Hughes" <KevanHughes@discussions.microsoft.com> wrote in message
news:E618D55C-0648-4B96-BC7B-80F45FDFA70F@microsoft.com...
> Guys,
>
> I have used the keyascii code.. How can i get rid of the annoying BEEP
> when
> ENTER key is pressed ?
>
> Thanks
That "KeyAscii = 0" line should take care of the beep.
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
| |
|
|
"Kevan Hughes" <KevanHughes@discussions.microsoft.com> wrote in message
news:E618D55C-0648-4B96-BC7B-80F45FDFA70F@microsoft.com...
> Guys,
>
> I have used the keyascii code.. How can i get rid of the annoying BEEP
when
> ENTER key is pressed ?
>
> Thanks
If you properly implemented Larry's example code, you shouldn't be getting
the beep. The 'KeyAscii = 0' should take care of that.
--
Mike
Microsoft MVP Visual Basic
[color=darkred]
>
> "Larry Serflaten" skrev:
>
box.[color=darkred]
next[color=darkred]
next[color=darkred]
| |
| Gary Nelson 2005-05-27, 3:55 am |
| Bruce,
"Bruce Hildebrand" <wizard@wizardnco.com> wrote in message
news:eyxLDaDMFHA.3196@TK2MSFTNGP10.phx.gbl...
> 1) when i first run the app, position the cursor to the first text box.
>
> 2) have the three text boxes accept the enter key and proceed to the next
> text box.
>
> What is the best way to accomplish this?
>
> Thanks in Advance.
>
>
1) Put the textboxes in proper tab order
2) Set the KeyPreview on the form to true and add the following.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then SendKeys "{TAB}"
End Sub
|
|
|
|