Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to set "enter" ?

Posted on 1999-07-24
17
Medium Priority
?
154 Views
Last Modified: 2010-04-30
i has i text box.
i want the user write some text on it and after that press the enter key.

the problem is how ? and whats the code ?

thank.
0
Comment
Question by:JOHNHO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 2
17 Comments
 
LVL 2

Accepted Solution

by:
alokanant earned 200 total points
ID: 1527074
u can use the following code in the key press event of the text box -

if (keyascii = vbkeyreturn) then\
   sendkeys "{TAB}"
end if

i think u want that when the user presses enter the focus should shift to the next control.

hope this helps.

alok
0
 

Author Comment

by:JOHNHO
ID: 1527075
i havent try the code yet.
for your information.
i want the user write a text into that text box.
and after that press the enter key.

the system will perform the thing that user has enter the text in the text box.
like show form or perfoem function.

i hope u inderstand what i mean.
thanks.
0
 

Author Comment

by:JOHNHO
ID: 1527076
i has use your code.
i put the hole code in the text box()text1_change )status.
but why nothing happend ?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:KDivad
ID: 1527077
I think you want something like:

Sub Text1_KeyPress(KeyAscii As Integer)

If Not KeyAscii = 13 Then Exit Sub
KeyAscii = 0 ' Use if you don't want the enter key
' doing anythiing else
Select Case LCase$(Text1.Text)
Case "show form"
    Form1.Show
Case "hide form"
    Form1.Hide
Case "open notepad"
    x = Shell("C:\Windows\Notepad.exe")
...'Enter other
...'possibilities
...'here
Case Else
    MsgBox "Unrecognized command"
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
End Select

End Sub

Hope this helps!
0
 

Author Comment

by:JOHNHO
ID: 1527078
thanks, i can do it now !!

but how about instead of using "enter" key , now i want to using "F3" key.
whats the code ?

and can u give me the details so next time i no need to bother you again,
lets say instead of using "enter","F3" , how about the other key word like "a" ,"b"
or "c".
please explain for me more details in learning to put the key
thanks.

0
 

Author Comment

by:JOHNHO
ID: 1527079
btw, what
If Not KeyAscii = 13 Then Exit Sub
      KeyAscii = 0 ' Use if you don't want the enter key

keyascii= 13 mean ?
keyascii= 0 mean ?

please explain more detail for me if i want to put the other function instead of "enter"
?
thanks
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1527080
Replace the code I gave you with this one, because the code I gave you won't work with the "F" keys (F1, F2, ... F12).

Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

If Not KeyCode = 13 Then Exit Sub
KeyCode = 0 ' Use if you don't want the key
' doing anythiing else
Select Case LCase$(Text1.Text)
Case "show form"
    Form1.Show
Case "hide form"
    Form1.Hide
Case "open notepad"
    x = Shell("C:\Windows\Notepad.exe")
...'Enter other
...'possibilities
...'here
Case Else
    MsgBox "Unrecognized command"
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
End Select

End Sub

I would suggest replacing "KeyCode = 13" with "KeyCode = vbKeyReturn". For a complete list of the built in keycode constants, check the vb help file and search for "keycode". That list in the help file will contain a list of KeyCode constants for each and every key. One note, however, use "KeyCode = vbKeyA" for "a" and "KeyCode = vbKeyA And Shift = vbShiftMask" for "A".

Need any more help, just holler.
0
 

Author Comment

by:JOHNHO
ID: 1527081
i still not understand, and i already your second code, but nothing happend.

can you give complete code by using F3 ? after that i will know what you mean ,
thanks.

0
 

Author Comment

by:JOHNHO
ID: 1527082
plus information,
i has put
keyascii=114 (should be F3 key)

but why nothing happend when the time i press F3 key ?

is there something faults ?

i still not understaqnd, also when the time i press "a" , my text box just show me "a" word, even i already put keyascii=65 , what actually is happend ?

thanks.
0
 

Author Comment

by:JOHNHO
ID: 1527083
YES I CAN DO IT !!!
thanks a lot.

but 1 more thing still not understand.

i want to has 3 key codes.

1 is for my user to enter one job (thats is enter key)
1 is for my user to F3 to perform the other job
1 is for my user to press "a" botton to perform the other job.

how can i do it in 1 form,

confuse already.

thanks

0
 
LVL 5

Expert Comment

by:KDivad
ID: 1527084
Make sure you are using the KeyUp event and not the KeyPress event. Also, make sure you use KeyCode and not KeyAscii.

Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyReturn
    'Enter key was pressed, so execute first job
Case vbKeyF3
    'F3 key pressed, execute second job
Case vbKeyA
    '"a" key was pressed, execute third job
End Select

End Sub
0
 

Author Comment

by:JOHNHO
ID: 1527085
WOW YOU REALLY HELP ME THIS TIME !!!
thanks a lot friend.

please answer my new question.
thanks

0
 
LVL 5

Expert Comment

by:KDivad
ID: 1527086
No problem, though you did accept the wrong person's answer.
0
 
LVL 2

Expert Comment

by:alokanant
ID: 1527087
for kdavid,

is there a way to transfer the points to you?

alok
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1527088
Alokanant,

If I remember correctly, they can add points to my account but the only way to remove points from yours is to delete your account and have you start a new one. So call it an early/late birthday present and we can just leave it like that, ok? I don't play for the points anyway, so I don't really miss them.

Happy B-Day :-)
KDivad
0
 

Author Comment

by:JOHNHO
ID: 1527089
to kdavid ,
sorry because i has enter the wrong account.

how do you show me the way to transfer the points ?
or you can help me to answer my new question and i will increase the miss points that i didnt give it to you.
the question is in the new question section , please go there.

my question is , how do we block some person from presing some botton, assume it is F4 key ?
thanks , please go there. i m waiting for you.

thanks
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1527090
You can't transfer the points.

I'll look at your question.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question