March 9, 2002

Exiting a Nested Loop

Sometimes, you need to exit a nested loop early, and the break; statement will only let you exit one level of a loop. Use a flag to indicate if the loop should be exited. bool abort = false;for(int i = 0; (i < 100) && (! abort); i++){ for(int j

Using the createScreenCapture Method to Capture Your Screen

The Robot class in Java provides a special method to capture your screen. This method creates an image containing pixels read from the screen and returns a BufferedImage class object. Here is an example to capture your screen. The image will be saved into a JPEG file. /* * @(#)ScreenCapture.java

Sorting a String Alpabetically

To Sort a String in alphabetical order instead of ASCII order (i.e A,a,B,b not A….Z,a….z), use the Collator class from the Java.text package.Here

Reading Properties from a File

It’s not too much trouble to read a few arguments from the command line. It really becomes a problem if you have to read 50 or more arguments. One solution is to prepare a property file and mention all the properties in it. Then you can read the name of

Avoid Errors on Assigning Null Values

Whenever you read a database field, concatenate an empty string to the field value before assigning it to a variable or control property. This prevents the program from giving an error if a Null value is read from the field. Here

Passing ByVal to ByRef Parameters

By default, VB passes all arguments to a procedure by reference, which means the procedure can change the values of the variables you pass. However, there

Center Your Logo on MDI Forms

You can display a logo in the middle of your MDI form. The logo stays in the middle even when the MDI form is resized. After creating your own MDI form, add a standard form to your project and put an Image control named imgLogo on it. Instead of the

Contain Tab Groupings Within a Frame

The best way to work with the tab control is to set up a different frame for each tab. If you set the frames to be indexed, you can quickly move and make the correct frame visible with this code: ‘ Move and resize the frames to the tabstrip’ control

View the Right Side of a Truncated String

You see trailing ellipses (…) when VB truncates either the expression or data portion of a data tip (the mouse-hover watch value you get while debugging). This is great if you want to see the left side of a long string value, but not quite as compelling if you care

No more posts to show