Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to 'select text' on current form 3

Status
Not open for further replies.

themaj

Technical User
Apr 10, 2006
37
US
I'm looking to write one subroutine at the form level that will 'Select Text' on each Textbox as I tab through the form.
I don't necessarily want to add a sub to each textbox on the form.

Is this possible? Any ideas or suggestions?

Thanks
 
It is true that code containing subclassing is prone to crashes. But that happens in only development stages. Once the code is tested and complete and free from errors, subclassing will never crash your application.

In subclassing, you bypass VB and ask Windows directly to execute your code using function pointers. This turns off the safe environment of VBIDE and may cause your applciation to crash if Windows does not find the expected code pointed by the function pointer you passed to it.

>If you stop your program with the End button in the IDE, it will crash.
Yes, if subclassing is in effect, never stop your program using End button (or End statement in code).

>If you place a break point in your program, it will crash.
Not necessarily. Just placing breakpoints will not crash your code. However, if your code encounters a breakpoint and you make changes to your code in Break mode, chances are high that this will crash your code. The reason is that editing the code in Break causes VB to recompile the code on the fly which may invalidate the function pointer previously passed to Windows.

>And if there is an error and the program stops(in the IDE), it will crash.
Only unhandled errors may cause problems. There are still chances that you escape a crash safely. When you encounter the error, click Debug and try to skip the statement which is causing the error by dragging the code pointer or using 'Set Next Statement' command (Ctrl+F9). Chances are good that you may prevent a crash. After that, close your program and correct the error in design mode.

Here are a few cautions when using subclassing.[ol][li]Save your work frequently.[/li][li]Prefer Debug.Print or MsgBox for debugging instead of putting breakpoints and stepping through your code.[/li][li]Always start your program using 'Start With Full Compile' command (Ctrl+F5) which atleast checks your whole program for syntax and compile errors and warns you in advance. Otherwise you will encounter those errors after subclassing is in effect when VB tries to execute that erratic code.[/li][li]Never end your program using End button or End statement. Always do that by clicking the Close button on your form or Unload statement in code.[/li][/ol]Subclassing is a very powerful and popular techniques and allows you to do thing which are not possible in VB without using third-party DLLs or ActiveX controls, which may also have used subclassing to achieve the same. As I told above, there are hundreds of subclassing examples on this site, alone in this forum.

As far as crashing of above code is concerned, I think you are doing something wrong or missing some step. I just tested it again and found OK. Perhaps Bob has also tested it. Avoid the End button on the toolbar.
 
No, I hadn't, but I just did and it works as expected. I did indeed crash the program using the stop button. :) Very nice stuff, and very good general practical advice on programming with the API.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top