Cricinfo Live Scores

Saturday, March 29, 2008

Restrict Keys in vba textbox

Hi, when i went to work out with my VBA application then i faced a problem of restricting
key press in my price textbox. So, i went on searching and searching in the internet. And
at last found a solution to it. Take a look on it.

Private Sub txtMasterPrice_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, txtMasterPrice.Text, "-") > 0 Or txtMasterPrice.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, txtMasterPrice.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub

Saturday, March 22, 2008

VBA: 255 string length problem

I had a very strange experience with my VBA application of MIS.
Two days past away but there was no solution for this problem.
The problem was my query length was crossing 255 characters length
and i was receiving error in the vba.

But, most interesting thing after a long investigation i discovered that
actually string length is not fixed to 255. Actually vba does not have
such kind of problems.

The problem was that i was using debugger to go through my logic paths
as i always do when testing application result; i was just investigating
my string length the debugger.

And, every time it was limited to 255 chars. Very unusual! When i get bored
and let the program to run for anything then i saw that my operation was
successful.

So, i come to the solution there is no problem with string length in VBA. Actually
debugger is not able to show you the string value over 255 chars.

It was a happy moment for me. So much pain i had gone through for that string......

Happy Programming.

Author
Kazi Masudul Alam
Software Engineer

Wednesday, March 19, 2008

xml and xsl

So, after a long time again in my little newspaper.

XSL stands for EXtensible Stylesheet Language.

The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based style sheet language.

XSLT stands for XSL Transformations. In this tutorial you will learn how to use XSLT to transform XML documents into other formats, like XHTML.

Let us go for """xsl:template""" . It is a very nice tool of xsl which takes a lot of pressure out of
your head. I will show you some smart implementation of this.

Here are 3 source files. You can download and run the xml in your browser. Go through it carefully and learn about the "template-match" http://www.w3schools.com/xsl/default.asp.
And compare it with the source files. It will be a nice experience.

topic.xml
topic.xsl
ui.xsl

Sunday, March 16, 2008

Struts 2: Basic Application

You can learn struts-2 from http://www.roseindia.net.

Here is a basic application for struts 2 the startup application for

Download the source code from here

Saturday, March 1, 2008

Design Pattern (GOF): Structural Pattern : Bridge

Definition

Decouple an abstraction or interface from its implementation so that the two can vary independently.

Where to use & benefits

Examples

If you have a question database, you may want to develop a program to display it based on the user selection. The following is a simple example to show how to use a Bridge pattern to decouple the relationship among the objects.

import java.util.*;

//abstraction
interface Question {

public void nextQuestion();
public void priorQuestion();
public void newQuestion(String q);
public void deleteQuestion(String q);
public void displayQuestion();
public void displayAllQuestions();
}

//implementation
class QuestionManager {

protected Question questDB; //instantiate it later
public String catalog;

public QuestionManager(String catalog) {
this.catalog = catalog;
}

public void next() {
questDB.nextQuestion();
}

public void prior() {
questDB.priorQuestion();
}

public void newOne(String quest) {
questDB.newQuestion(quest);
}

public void delete(String quest) {
questDB.deleteQuestion(quest);
}

public void display() {
questDB.displayQuestion();
}

public void displayAll() {
System.out.println("Question Catalog: " + catalog);
questDB.displayAllQuestions();
}
}


//further implementation
class QuestionFormat extends QuestionManager {

public QuestionFormat(String catalog){
super(catalog);
}

public void displayAll() {

System.out.println("\n~~~~~~~~~~~~~~~~~~~~~~~~");
super.displayAll();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~");
}
}

//decoupled implementation
class JavaQuestions implements Question {

private List questions = new ArrayList();
private int current = 0;

public JavaQuestions() {
//load from a database and fill in the container
questions.add("What is Java? ");
questions.add("What is an interface? ");
questions.add("What is cross-platform? ");
questions.add("What is UFT-8? ");
questions.add("What is abstract? ");
questions.add("What is Thread? ");
questions.add("What is multi-threading? ");

}

public void nextQuestion() {
if( current <= questions.size() - 1 )
current++;
}

public void priorQuestion() {
if( current > 0 )
current--;
}

public void newQuestion(String quest) {
questions.add(quest);
}

public void deleteQuestion(String quest) {
questions.remove(quest);
}

public void displayQuestion() {
System.out.println( questions.get(current) );
}

public void displayAllQuestions() {
for (String quest : questions) {
System.out.println(quest);
}
}
}


class TestBridge {
public static void main(String[] args) {

QuestionFormat questions = new QuestionFormat("Java Language");

questions.questDB = new JavaQuestions();//can be hooked up with other question class
//questions.questDB = new CsharpQuestions();
//questions.questDB = new CplusplusQuestions();

questions.display();
questions.next();

questions.newOne("What is object? ");
questions.newOne("What is reference type?");

questions.displayAll();
}
}

Author
Kazi Masudul Alam