Computing.Net > Forums > Programming > vb9 keypress

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vb9 keypress

Reply to Message Icon

Name: wille
Date: May 3, 2008 at 08:05:02 Pacific
OS: WINDOWS XP Home Edition
CPU/Ram: 3.2GHz
Comment:

Hi, I'm having some trouble with this program. I want a function to execute when a textbox contains certain text and the user presses the return key.
I tried the keypress function but then the function that I wanna execute on keypress return is executed by whatever key I press.

Like this:
say I write "exit" in the textbox and then press enter. then the code would be:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.Text = "exit" Then End
End Sub

but the program will end even if I press some other key like if I write "exits" the program'll check when the textbox contains "exit" on keypress "s" and then it will execute then command End and close.
Any help will be appreciated.

Live the life as you know it
/ Wille



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: May 3, 2008 at 09:40:31 Pacific
Reply:

You need to be looking at what calls the function and what happens when the function returns.

You should never end a VB application with the End statement, it will cause all kinds of problems which this seems to be one of them. End is a throwback to DOS Basic and should only be used in conjunction with Stop as a debugging tool.

The correct way to terminate a VB application is to close all active forms then the application will terminate. That way you can ensure that all open files are properly closed and you don't end up with corrupted data and bits of the application being left in memory. End does just that, kills the application stone dead without any cleanup operations.

Stuart


0

Response Number 2
Name: wille
Date: May 3, 2008 at 13:19:52 Pacific
Reply:

OK thanks alot for the end advice. Just, how do I check what calls the function? I meen, I do know since I press the button that executes the function but the program doesn't. Is there a variable for the key that executed the function? Because that would be great.
Thanks again.

Live the life as you know it
/ Wille


0

Response Number 3
Name: Razor2.3
Date: May 5, 2008 at 19:00:30 Pacific
Reply:

if I write "exits" the program'll check when the textbox contains "exit" on key press "s" and then it will execute then command End and close.
I'm not seeing an issue here; you want to close the application when the textBox = "exit", and your scenario does indeed fulfill your test. How is this not the behavior you want?

Is there a variable for the key that executed the function?
Boilerplate code exists for a reason. I'd check the documentation on
TextBox.KeyPress(Object, KeyPressEventArgs).


0

Response Number 4
Name: wille
Date: May 8, 2008 at 09:43:21 Pacific
Reply:

that isn't the behavior becaus if I want to type exits or exit and somthing avther that then it'll close. however I'll check that site thanks very much.

Live the life as you know it
/ Wille


0

Response Number 5
Name: Razor2.3
Date: May 8, 2008 at 11:17:16 Pacific
Reply:

that isn't the behavior becaus if I want to type exits or exit and somthing avther that then it'll close.
Then I suggest you use a different event. Possibly TextBox.Leave


0

Related Posts

See More



Response Number 6
Name: wille
Date: May 11, 2008 at 10:40:07 Pacific
Reply:

Never mind I've found out how it's done but however thanks a million for all help. :D

Live the life as you know it
/ Wille


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: vb9 keypress

F5 KeyPress event on DataGrid www.computing.net/answers/programming/f5-keypress-event-on-datagrid/10802.html

In Pascal keypressed, in ANSI C..?? www.computing.net/answers/programming/in-pascal-keypressed-in-ansi-c/13486.html

auto keypress on client application www.computing.net/answers/programming/auto-keypress-on-client-application/16056.html