August 21, 2003

Handling Binary Files in Perl

For some reason, there exists a common misconception that there is no cross-platform, built-in way in Perl to handle binary files. The copy_file code snippet below illustrates that Perl handles such tasks quite well. The trick is to use “binmode” on both the input and output files after opening them.

Insert an Image into a Database Using JDBC

//create the file object,//set the image to the statement object as//binary streamtry{ … File fileObject = new File(…); FileInputStream fisObject = new FileInputStream(fileObject); PreparedStatement pstmt = conn.prepareStatement(“insert into IMAGE_TABLE values (?,?)”); pstmt.setString(1,fileObject.getName()); pstmt.setBinaryStream(2,fis,(int)file.length()); pstmt.executeUpdate(); …… } catch(…) { … }

Code an Event Procedure for Each Textbox

If you want to code an event procedure (such as GotFocus) for each textbox on a freshly designed form, you must switch manually from the Change event to the GotFocus event for each one. This can be annoying and tedious, especially when many textboxes dont belong to a control array.

Return Roman Numerals

This VB procedure returns decimal numbers (integers) as Roman numerals (a string), ranging from 1 to 4999. Numbers outside this range return the same number as a string. The optional parameter iStyle allows two different numerical styles: standard (4 = iv, 9 = ix, and so on) when iStyle =