Friday, 29 April 2011

Building a Crossword Control

If you decide to build a Crossword Control, remember to keep it concise as you get bogged down by too many ideas. Create a control array for the text boxes and labels. The below code shows how an auto increment is used for the across and down options. Loops are used to extract characters from answer arrays to be placed in the result grid.
Private Sub UserControl_Initialize()
Dim i, j, k As Integer
Dim l, m, n As Integer
Dim o As Integer
Dim across_increment(25) As Integer
Dim down_increment(25) As Integer
'i = j = 0
i = 1
j = 0
k = 0
o = 0
across_increment(0) = 3
across_increment(1) = 1
across_increment(2) = 3
across_increment(3) = 1
Dim across_ques_arr(25) As String
Dim across_ans_arr(25) As String
Dim down_ques_arr(25) As String
Dim down_ans_arr(25) As String
across_ques_arr(0) = "Termite Eating Nocturnal African Mammal"
across_ans_arr(0) = "Aardvark"
across_ques_arr(1) = "Nautical Term Used for Hailing A Person"
across_ans_arr(1) = "Ahoy"
across_ques_arr(2) = "Fine Smooth Cotton Thread Used for Stockings in Northern France"
across_ans_arr(2) = "Lisle"
across_ques_arr(3) = "Native Or Inhabitant Of Denmark"
across_ans_arr(3) = "Dane"
down_ques_arr(0) = "Horse Drawn Vehicle Used in Ancient Fighting and Racing"
down_ans_arr(0) = "Chariot"
down_ques_arr(1) = "Doctor Of Letters"
down_ans_arr(1) = "DLitt"
k = k + across_increment(0)
Do While (j <= 3)
Do While (i <= Len(across_ans_arr(j)))
Text1(k).Text = "" & Mid(across_ans_arr(j), i, 1)
i = i + 1
k = k + 1
Loop
i = 1
j = j + 1
k = k + across_increment(j)
Loop
l = 1
m = 0
n = 0
down_increment(0) = 6
'down_increment(1) = 2
Do While (m <= 1)
o = n
Do While (l <= Len(down_ans_arr(m)))
Text1(n).Text = "" & Mid(down_ans_arr(m), l, 1)
l = l + 1
n = n + 13
Loop
n = o + down_increment(m)
l = 1
m = m + 1
Loop
Dim x As Integer
Dim y As Integer
Dim str As String
x = 0
y = 0
Do While (x < 25)
If (Len(across_ques_arr(x)) > 40) Then
str = Left(across_ques_arr(x), 40) & vbCrLf & Right(across_ques_arr(x), Len(across_ques_arr(x)) - 40)
Label2(x).Caption = "" & (x + 1) & ") " & str
Else
Label2(x).Caption = "" & (x + 1) & ") " & across_ques_arr(x)
End If
x = x + 1
Loop
Do While (y < 25)
If (Len(across_ques_arr(y)) > 40) Then
Label3(y).Caption = "" & (y + 1) & ") " & down_ques_arr(y) & vbCrLf
Else
Label3(y).Caption = "" & (y + 1) & ") " & down_ques_arr(y)
End If
y = y + 1
Loop
End Sub

Building Dynamic HTML Pages

Dynamic HTML is used to refer to a combination of HTML, CSS, Stylesheets and Scripts. The object model of HTML pages is governed by the W3C, which is constantly working towards improving usage across browsers and making pages more script friendly. The W3C DOM WG is the group working towards this goal. Browsers have always had to struggle with the static nature of HTML pages. The Internet Explorer browser is far more advanced in this regard compared to Netscape's Netscape Navigator.

Some of the features of Dynamic HTML include:
Absolute Positioning: This is the ability to use cascading style sheets to change the position of objects on pages to produce floating or dynamic effects.
Behaviors: This again refers to cascading style sheets with the capability to respond to user behavior such as mouse or keyboard actions.
Data Binding: Refers to the interaction of web pages with databases from the browser.
DOM: Or the Document Object Model is the method or schema by which page elements are seen as structured objects which can be manipulated through code.
Dynamic Content: The challenge of dynamically updating web page content is achieved by manipulating headings, body text and paragraph content through code.
Dynamic Styles: You can change the style or the way your HTML document looks by changing the font, color or style of the web page by the click of a mouse or by hover.
Scriptlets: It refers to scripts which run in the HTML pages.
ActiveX Controls/Applets: ActiveX Controls and applets are standalone objects that let users perform specialized tasks in static HTML pages.
How to Change Styles Using Dynamic HTML
It is possible to change the styles of page objects dynamically. This is done by moving the mouse over it or by clicking on it.
&lt;HTML&gt;
&lt;Head&gt;
&lt;Title&gt;Dynamic Styles&lt;/Title&gt;
&lt;/Head&gt;
&lt;Body&gt;
&lt;Center&gt;
&lt;H1&gt;Dynamic Behaviors&lt;/H1&gt;
&lt;Div onmouseover="this.style.fontStyle='34'"&gt;
Enlage this Text!
&lt;/Div&gt;
&lt;/Center&gt;
&lt;/Body&gt;
&lt;/HTML&gt;

 

Apache POI in Action

As most of us use MS-Excel files in our daily activities we need to create, maintain or update them regularly or once in a while. Using a Java API is perhaps the easiest way to manipulate these documents. We will see actual examples of applications wanting to create, modify and update MS-Excel files.

The Bugsby Restaurant
We will use an example of a eat-in restaurant for illustrating examples of POI-HSSF. Bugsby restaurant is based in New Orleans and has patrons arriving at its doors from all over the country. Bugsby has an order maintainance system it maintains from a custom made application which receives orders for items from patrons and registers the same in the database. This application requires to generate MS-Excel file extracts at regular intervals for stock taking purposes.
This include daily orders list generated at the end of the day, daily inventory statistics also generated at the end of the day, daily number of drinks distributed or sold in the bar details, weekly and monthly reports of the same.

Daily Orders List
The Daily Orders list is generated at the end of the day at day closure and the MS-Excel files are generated as records or backups of data generated in the Order Maintenance application. This is very similar to reports generated from an application for identical reasons or purposes with the only difference being the MS-Excel files act as actual data storage or backup for application data. This might not be true for reports as they are only preview material and do not provide a mechanism for storing the generated data.
Creating a New Workbook, New Worksheet and New Cells
package BugsbyOrderMaintainence;
/**
*
* @author Visual Basic Premier
*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.*;
public class Orders_List_Create {
public static void Orders_List_Create(){
try{
FileOutputStream fileOut = new FileOutputStream("C:\\Users\\Documents\\JavaApplication6\\Orders_List.xls");
// create a new workbook
Workbook wb = new HSSFWorkbook();
// create a new sheet
Sheet s = wb.createSheet("Orders List");
CreationHelper createHelper = wb.getCreationHelper();
s.autoSizeColumn((short)0); //adjust width of the first column
s.autoSizeColumn((short)1);
s.autoSizeColumn((short)2);
Row row0 = s.createRow((short)0);
Cell cell0 = row0.createCell(0);
Cell cell1 = row0.createCell(1);
Cell cell2 = row0.createCell(2);
Cell cell3 = row0.createCell(3);
Cell cell4 = row0.createCell(4);
Cell cell5 = row0.createCell(5);
Cell cell6 = row0.createCell(6);
Cell cell7 = row0.createCell(7);
Cell cell8 = row0.createCell(8);
cell0.setCellValue("Order Id");
cell1.setCellValue("Order Number");
cell2.setCellValue("Order Date");
cell3.setCellValue("Item Name");
cell4.setCellValue("Item Price");
cell5.setCellValue("Item Quantity");
cell6.setCellValue("Order Cost");
cell7.setCellValue("Order Table");
cell8.setCellValue("Waiter Name");
wb.write(fileOut);
fileOut.close();
}catch(Exception e){System.out.println(e);}
}
public static void main(String[] args) {
Orders_List_Create ord_list= new Orders_List_Create();
ord_list.Orders_List_Create();
}
}

 Created Orders List
The output of the above program with the created workbook, worksheet and cells are shown.

Friday, 22 April 2011

The Single Character User Control

The below example is of a user control which pops up a message of the single character's entered in a textbox. Every time a character is entered a message box is popped up and the user gets an idea of the character enetered.
Private Sub Text1_KeyPress(KeyAscii As Integer)
MsgBox "" & Chr(KeyAscii)
End Sub
The same action can be performed for a password box, similiar to a text box, enabling the user to view the input.

Thursday, 21 April 2011

Using Microsoft Silverlight for Applications

If you ever need to create interactive and engaging applications for mobile and web applications, Silverlight is the ideal choice. The Plug-in works on the .NET framework and on different browsers. You can build rich applications for great interactivity. It has over 40 features, great video quality and good performance. It also has support for Microsoft Visual Studio with CPU, dynamic memory and threading in applications.

It is used in applications in:
  • Media
  • Business
  • Mobile

Wednesday, 20 April 2011

The Timer Control

Option Explicit
Dim d1 as Date
Private Sub Form_Load()
'The Timer
Timert.interval=1000
Timert.Enabled=True

'Performing an activity every 1 second
End Sub

Private Sub Timer_Timer()
'Displays the Second interval in the Date
text1.text=Now + 1
End Sub

Monday, 18 April 2011

Building a Simple Interest Calculator

Dim Principal as Currency
Dim Interest as Single
Dim Term as Integer
Dim Payment as Currency

Principal=val(txtPrincipal.Text)
Interest=val(txtInterest.Text)/100
Term=val(txtTerm.Text)*100
Payment=Principal*(Interest/(1-(1+Interest)*-Term)

Fundamental Visual Basic Programming

Variable List:
String-One Byte
Integer-Two Bytes
Long Integer-Four Bytes
Single(Floating Point)-Four Bytes
Double-Eight Bytes
Currency-Eight Bytes
Boolean-Two Bytes

Declaring a Variavle:
Dim x as Integer