473,473 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Capture ENTER key while working with textbox

phillipsbrian
8 New Member
I have achieved a good amount of programme as my first VB programme. So far all the bugs are out but!
I have been trying to work with a TEXTBOX and am really confused.

my aim is to have the user type two numbers into a textbox, and then to operate on those numbers and store them into another textbox window.
I have tried various ways without sucess. ie. entering two numbers and hitting return, the programme then looks for the chr(13) and passes on to the next input, but the return key is not seen. If I enter a space instead of return and the programe looks fo a space, then that is detected. Can anyone please explain what is happening?
Thank you
Jun 2 '07 #1
5 17781
Dököll
2,364 Recognized Expert Top Contributor
I have achieved a good amount of programme as my first VB programme. So far all the bugs are out but!
I have been trying to work with a TEXTBOX and am really confused.

my aim is to have the user type two numbers into a textbox, and then to operate on those numbers and store them into another textbox window.
I have tried various ways without sucess. ie. entering two numbers and hitting return, the programme then looks for the chr(13) and passes on to the next input, but the return key is not seen. If I enter a space instead of return and the programe looks fo a space, then that is detected. Can anyone please explain what is happening?
Thank you
Hello, phillipsbrian!

I think you mean adding two numbers and adding the result in a textbox. If this is the case:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Total_Click()                        'total command button
  2.     Dim Num_One As Integer
  3.     Dim Num_Two As Integer
  4.     Dim Total_Results_Num As Integer
  5.  
  6.     Num_One = Int(Text1.Text)
  7.     Num_Two = Int(Text2.Text)
  8.  
  9.     Total_Results_Num = Num_One + Num_Two 
  10.     Text3.Text = Total_Results_Num
  11.  
  12. End Sub   
  13.  
(1) You have added two textboxes, namely, Text1.Text + Text2.Text and adding the results to Text3.Text

(2) You have also also dimensioned Num_One & Num_Two, lastly Total_Results_Num for integer place holders

If this is not what you hoped to achieve, please let us know.

In a bit!

Dököll
Jun 2 '07 #2
phillipsbrian
8 New Member
Thanks dok,

but sorry that was not what I wanted.

I wish the user to enter two numbers( ex: 44) followed by a return, into textbox1, and be able to trap the return key.I will then have the two numbers in a string for further use!
In other words, once I have a return key entered I know the user has finished input and we can take the "textbox.text" into a string and leave the routine with the string carrying the double number.

Something like the old fashioned getkey argument, where one can accept keys one after the other into a string until a enter key or similar is entered and then drop the input and operate on the string!

Best regards, brian
Jun 4 '07 #3
Killer42
8,435 Recognized Expert Expert
Ok, I'm talking VB6 here - so if you're using a later version some or all of this may be useless to you.

Generally, you would probably do something like putting a command button on the form (hidden away where the user can't see it, if you like). Set the .Default property of the button to True, and it will be triggered when the user presses Enter. (I think there's nothing you can do to stop it beeping on Enter, but I could be wrong.)

Another alternative is to put code in the KeyPress or KeyDown event for the textbox, to watch what is happening. Or if you turn on the KeyPreview property of the form, it will get to see them first, before the textbox does.

(By the way, I've modified the title of the thread, in line with the site posting guidelines. This makes it more useful for anyone who later comes searching for similar information.)
Jun 4 '07 #4
Mohan Krishna
115 New Member
Hi Brain,

May be I am very late and Hope you might have got the solution, but, if my this reply helps someone, i would be very happy.

If I got ur problem understood correctly,

in the Text_KeyPress() procedure, put this sentence if I am correct

If keyascii = vbkeyreturn then ...

Hope I reached this problem.

With Regards,
Mohan
Mar 9 '08 #5
In the KeyPress sub, the
"if keyascii = vbkeyreturn then" works just hunky and
dorey .... follow that with
keyascii = 0 to supress the beep .....
Oct 24 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: marcia | last post by:
How can I capture (i.e., write an event handler) that runs after I press the "Enter" key? I'd like to prevent a Web Form from being submitted when the "Enter" key is pressed following the typing...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
0
by: Tomaz Koritnik | last post by:
I have an UserControl with a Textbox on it. TextBox captures keys (I assume via overridden ProcessCmdKey method) and doesn't pass them onto parent (by not calling base.ProcessCmdKey) therefore...
1
by: Tomaz Koritnik | last post by:
I have an UserControl with a Textbox on it. TextBox captures keys (I assume via overridden ProcessCmdKey method) and doesn't pass them onto parent (by not calling base.ProcessCmdKey) therefore...
2
by: TC | last post by:
Hello, I need to build a very simple text editor. The requirement is that the input screen should be divided into 'm*n' cells ('m' rows, 'n' columns, with each cell of a fixed size). Whenever...
3
by: GS | last post by:
If I were to capture enter key on keyup event of an GUI object like comboBox box, How do I avoid killing ctrol-c, controlv, controlx, shift-insert, shiftdelete, contrl-insert
7
by: Marc | last post by:
Hi, I want my user to be able to rename a button control by selcting rename from a menu. This then opens a text box in which to enter the new name in. I want the button control to...
4
by: nkoier | last post by:
Hi, I've been going crazy trying to figure out what's wrong with our Asp.Net 2.0 intranet site. At the very top of our main page I provide a TextBox and a Button for submitting Google searches....
4
by: samxx | last post by:
Hi, I need to capture Enter key (keyCode==13) in an designMode enabled iframe of my chat sending virtual textbox. it's a wysiwyg posting. However I have the following code working fine in IE7 but...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.