Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: vb9 keypress

Original Message
Name: wille
Date: May 3, 2008 at 08:05:02 Pacific
Subject: vb9 keypress
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


Report Offensive Message For Removal

Response Number 1
Name: StuartS
Date: May 3, 2008 at 09:40:31 Pacific
Subject: vb9 keypress
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 2
Name: wille
Date: May 3, 2008 at 13:19:52 Pacific
Subject: vb9 keypress
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: May 5, 2008 at 19:00:30 Pacific
Subject: vb9 keypress
Reply: (edit)
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).


Report Offensive Follow Up For Removal

Response Number 4
Name: wille
Date: May 8, 2008 at 09:43:21 Pacific
Subject: vb9 keypress
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: May 8, 2008 at 11:17:16 Pacific
Subject: vb9 keypress
Reply: (edit)
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

Report Offensive Follow Up For Removal

Response Number 6
Name: wille
Date: May 11, 2008 at 10:40:07 Pacific
Subject: vb9 keypress
Reply: (edit)
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


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: vb9 keypress

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC