Question:
What is the significance of "KeyAscii = 13" in Visual Basic?
anonymous
2007-08-06 08:34:29 UTC
Can you please explain about this part of the code?


Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1.Value = True
End Sub


Does changing the MaxLength property of Text2 to 9 characters affect the program stability in this case?
Six answers:
anonymous
2007-08-06 08:43:44 UTC
Ascii 13 is the Enter key on the keyboard or more techie called a carriage return. This will tell the program if enter is hit then set the value of command1 to true. Changing the max length will not affect this piece of the code.
anonymous
2007-08-06 08:42:54 UTC
When you press the key ENTER or RETURN.

The number 13 is the code for the key ENTER. Also you can use:

If KeyAscii = vbkeyEnter Then Command1.Value = True
TreyJ
2007-08-06 08:44:10 UTC
13 is the ASCII code for the Enter key. So what this method is doing is seeing if the user hits Enter, and if so, it presses the button Command1.



To answer your other question, I tested it and it seems to still call KeyPress even if the field is full, so you should be okay.
anonymous
2016-04-02 04:24:28 UTC
For the best answers, search on this site https://shorturl.im/avQ3g



'create a new form 'Example code: Private Sub Form_KeyPress(KeyAscii As Integer) MsgBox KeyAscii End Sub 'Now press any key ' the Msgbox will give you pressed key's AsciiCode
anonymous
2016-10-16 11:19:19 UTC
Keyascii
anonymous
2016-08-24 15:10:32 UTC
Every time I ask a question, even if it's the simplest one, they cannot give me a proper informed answer on this site. Wtf happened to people who actually take the time to answer..


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...