Posts

Showing posts from April, 2016

T-SQL: Prudent use of Select ... As

Every database developer using T-SQL will agree that the Select ... As feature allows one to easily grab values into a variable. However, after I got my fingers burnt recently, I had to share this to remind everyone how important it is to exercise prudence with its usage. Given the table below, assuming its an SQL table named Students. Id Name Age Class 1 Fade Ayomi 10 5 2 Oluwayomi Ojo 9 6 3 Kemi Mide 8 4 And given the SQL statements below which performs certain operations on the table given above declare @ StudentAge int ; select @ StudentAge = Age from Students where Id = 1 ; set @ StudentAge = Age * 2 ; select @ StudentAge = Age from Students where Id = 5 ; select @ StudentAge as AgeSelected; So what would AgeSelected resolve to according to the provided information? Ordinarily, one would expect AgeSelected to be NULL however, since @StudentAge carried a value initially, and the row described in the where clause do not exist in the table, @Stud

Determine Appropriate Font-Size for Text iTextSharp

Image
Background: I use CorelDraw a lot to lay out my reports before writing the iTextSharp code to generate them. It gives me a fair idea of how to position report elements and keeps me from doing guesses or trial and error. This was the case when I worked on the ID Card project for Delta State University: I had the ID card neatly laid out and the school loved the design. Issue: Now, everyone knows we normally have long names in Nigeria. My design template had a name that was 10 characters long and I used 28pt points for this text. What I wanted to achieve however is that, for names that will not be able to fit into the maximum space allowed for the name text at the 28pt used in the design template, the system should use the maximum font size that will permit the name to fit in the space available. Its a simple problem, but wasn't so easy to resolve. Solution: public Font GetSafeFont ( string DisplayText, Font FontToUse, float SafeLength, float StartingSize) {