Posts

Showing posts from June, 2010

Java XML getElementById returning null, fix using XPath

I had almost lost my breath over this issue for an entire day and found that the solutions provided in most blogs and forums doesn't for a tight schedule. Here, I am sharing the method that finally worked for me. I am using Netbeans with the default DOM parser(SAX Parser) provided in javax package. The problem is that the method: Document.getElementById(String id) returns null unless we explicitly specify the type of an attribute as ID. The Javadoc for this method says: "The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null." The type of attributes can be defined in two ways, either by using a DTD or xml schema. But, because I was really in short of time, I didn't want to go through all the complexities of implementing a DTD or XSD validation. Trust me…

VB - Using ADO to Connect to an ODBC Datasource

Connecting to a Database can be done in different ways. Personally I prefer ODBC because it allows to change the filename or path easier, just by using the ODBC administrator in the control panel. Dim ad as ADODB.Connection set ad=New ADODB.Connection ad.ConnectionString= "DSN=" & DataSourceName & ";UID=" & UserName & ";PWD=" & UserPassword ad.Open

java code sample for converting a number into English words

Hi Here is a java code sample for converting a number into English words. I think it will be helpful for your Application especially billing applications require these kind of applications public class NumToWord { public static String convertNum(double N) { System.out.println(N); double decimalpart; int num; boolean skip=false; int [] numword=new int[20]; String subtext=""; String numinWords=""; decimalpart=N-(int)N; num=(int)N; System.out.println(num); int i=-1; while (num>0) { i++; numword[i]=num%10; num=num/10; } for( ;i>=0;i--) { if(i%2==0&& i!=2 &&i!=0||i==1) { if(i==1 && numword.length>2) numinWords+=" And "; switch(numword[i]) { case 2: subtext="Twenty ";break; case 3: subtext="Thirty ";break; case 4: subtext="Fourty ";break; case 5: subtext="Fifty ";break; case 6: subtext="Sixty ";break; case 7: subtext="Seventy ";break; case 8: subtext="Eighty &…

Java - Get value of a Registry Key using Windows registry command line utility

import java.io.*; /** * * @author Rineez */ public class RegQuery { private static final String REGQUERY_UTIL = "reg query "; private static final String REGSTR_TOKEN = "REG_SZ"; private static final String REGDWORD_TOKEN = "REG_DWORD"; public static String getRegistryValue(String regKey, String valueName, String dataType) { try { String COMMAND=REGQUERY_UTIL + "\"" + regKey + "\"" + " /v" + ((valueName.equals(""))?"e":" "+valueName);//Gets default key value if valueName is blank Process process = Runtime.getRuntime().exec(COMMAND); StreamReader reader = new StreamReader(process.getInputStream()); reader.start(); process.waitFor(); reader.join(); String result = reader.getResult(); int p = result.indexOf(REGSTR_TOKEN); if (p == -1) return null; return result.substring(p + REGSTR_TOKEN.length())…

ActionScript - Customize the Flash Context Menu (Right Click Menu)

This tutorial will teach you how to customize the Flash context menu (right-click menu). This technique is applicable to absolutely any Flash project, regardless of size, length, or complexity.Everyone has seen the context menu that appears when you right-click on a Flash movie. By default, this context menu has a somewhat unprofessional appearance, and it has a couple of features that can severely disrupt the functionality of an ActionScript-driven Flash movie. The default suite of items that appear in the Flash context menu will vary depending on whether or not the Flash movie has multiple frames in its timeline.var menu:ContextMenu = new ContextMenu(); menu.hideBuiltInItems(); _root.menu = menu; var item:ContextMenuItem = new ContextMenuItem("Created by www.livares.com", liv); menu.customItems[0] = item; menu.customItems[1] = item1; function liv() { getURL("http://www.livares.com"); }