Showing posts with label how to. Show all posts
Showing posts with label how to. Show all posts

Tuesday, November 4, 2008

Convert amount to words in RPG ILE

I have had a situation where the amount had to be converted into words so that it can be printed on checks. A little googling got me to this solution. I had to convert it to the free form version for my use. There might be other/better versions out there, but this worked for me. You can find the original version (if the link is still active) here

      //  =============================================================
      //  =  Service program... NbrToWords / CvtNbrToWords           
      //  =  Description....... Service program to convert a number   
      //  =                     to words                                                          
      //  =  Amount needs to be converted into words for printing on  
      //  =  checks.                                                  
      //  =                                                          
      //  =  CrtRPGMod  Module( Your library/NbrToWords )       +             
      //  =             SrcFile( Your library/YourSrcFile )                  
      //  =                                                           
      //  =  CrtSrvPgm  SrvPgm( Your library/NbrToWords )       +            
      //  =             Export( *All )                  +            
      //  =             ActGrp( *Caller )                            
      //  =============================================================

     H NoMain

      //  -------------------------------------------------------------
      //  -  Procedure prototypes                                     -
      //  -------------------------------------------------------------

     D CvtNbrToWords   Pr           200A
     D  Number                       15S 0 Value

      //  -------------------------------------------------------------
      //  -  Global variables                                         -
      //  -------------------------------------------------------------

     D MaxGrps         C                   5

     D Words           S             13    Dim(99)
     D                                     CtData

     D Grps            S              8    Dim(MaxGrps)
     D                                     CtData

      //  =============================================================
      //  =  Procedure:   CvtNbrToWords                               
      //  =  Description: Convert number to words                     
      //  =============================================================

     P CvtNbrToWords   B                   Export

      //  -------------------------------------------------------------
      //  -  Procedure interface                                      -
      //  -------------------------------------------------------------

     D CvtNbrToWords   Pi           200A
     D  Nbr                          15S 0 Value

      //  -------------------------------------------------------------
      //  -  Variable declarations                                  
      //  -------------------------------------------------------------

     D AlphaNbr        S             15

     D WorkFld         DS
     D  Work3                         3
     D  Work2                         2    Overlay( Work3 : 2 )
     D  Work1                         1    Overlay( Work3 : 1 )

     D Count           S              5I 0
     D Pos             S              5I 0
     D Idx             S              5I 0

     D RtnWords        S            200A   Inz

      //  -------------------------------------------------------------
      //  -  Convert number to words - logic                          -
      //  -------------------------------------------------------------

      /Free

           Select;

           When Nbr = *Zero;
             RtnWords = 'zero';

           Other;
             If Nbr < *Zero;
               RtnWords = 'negative';
               Nbr = Nbr * -1;
             EndIf;

             EvalR AlphaNbr = %EditC(Nbr:'X');

             DoW Count <>
               Count += 1;
               Pos = (Count * 3) - 2;
               Work3 = %Subst(AlphaNbr : Pos : 3);

               If Work3 <> '000';

                 If Work1 <> '0';
                   Clear Idx;
                   Idx = %Int(Work1);
                   RtnWords = %TrimR(RtnWords) + ' ' +
                              %TrimR(Words(Idx)) +  ' hundred';
                 EndIf;

                 If Work2 <> '00';
                   Clear Idx;
                   Idx = %Int(Work2);
                   RtnWords = %TrimR(RtnWords) + ' ' + %TrimR(Words(Idx));
                 EndIf;

                 RtnWords = %TrimR(RtnWords) + ' ' + %TrimR(Grps(Count));

               EndIf;
             EndDo;

           EndSl;

           RtnWords = %Trim(RtnWords);

           Return RtnWords;

      /End-Free

     P CvtNbrToWords   E

** CtData Words
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
forty-three
forty-four
forty-five
forty-six
forty-seven
forty-eight
forty-nine
fifty
fifty-one
fifty-two
fifty-three
fifty-four
fifty-five
fifty-six
fifty-seven
fifty-eight
fifty-nine
sixty
sixty-one
sixty-two
sixty-three
sixty-four
sixty-five
sixty-six
sixty-seven
sixty-eight
sixty-nine
seventy
seventy-one
seventy-two
seventy-three
seventy-four
seventy-five
seventy-six
seventy-seven
seventy-eight
seventy-nine
eighty
eighty-one
eighty-two
eighty-three
eighty-four
eighty-five
eighty-six
eighty-seven
eighty-eight
eighty-nine
ninety
ninety-one
ninety-two
ninety-three
ninety-four
ninety-five
ninety-six
ninety-seven
ninety-eight
ninety-nine
** CtData Grps
trillion
billion
million
thousand
                                                 

Wednesday, November 7, 2007

How to determine if a data value is null

When we try to get data using a series of SQL joins, at some point, we are bound to hit a data element with a Null value. It took me a little bit of time the first time i came across such an error. This is how i dealt with it:


If TypeOf (MyDs.Tables(0).Rows(j).Item(3)) Is System.DBNull Then
' do something here

End If

Monday, August 6, 2007

Water heater goes kaput!

As if the problem of having to deal with the loss of a phone number was not enough, last week, our water heater literally decided to leave us high and dry (well, uh, not exactly dry as we live in this high humidity zone, but I suppose you get the point).

Though the need for hot water is not as crucial during the hot, hazy days of summer, we pampered souls still like the convenience of having hot water at the push of a lever. And then, there are the usual reasons when we cannot do without hot water (like bathing the children, washing clothes/dishes etc.).

Under those situations, our initial reaction would be to reach out for the phone and get in touch with a plumber/electrician that can solve our problem the fastest! Well, I too reacted along similar lines, but instead of hitting the phone book, I took to the web searching for plumbers. An online service allowed me to search for and send requests to plumbers in the area, but all it could find was one plumber who was at least a good half an hour away. To his credit, this plumber called and left a voicemail saying that he could help me get a new heater real fast. While waiting on his reply, I had been trolling the various forums trying to see if I could find suggestions to my predicament. Some went as far as recommending I replace both thermostats as well as both heating elements where as some others suggested I drain the heater tank and clean the elements. But none of them went so far as to suggest replacing the water heater itself.

Our water heater has an auto shut off feature that shuts off power to the heater if the tank temperature becomes too hot. My initial assessment told me that this was what was happening as the water from the faucets became very hot a few hours before it turned dead cold. So, I opened up the heater access panel and hit the reset button. This seemed to rectify the problem, but the next morning, I noticed that the water was hotter than normal. As anticipated, the auto shut off system jumped back in action and turned off the heater. The result? No hot water for the second time in as many days. Further searching on the net brought me to what seemed to be a knowledgeable suggestion from an experienced (plumbing?) mind. The suggestion was to replace the lower thermostat. The explanation? The lower thermostat might have gotten fried and so the lower element doesn’t know when to stop working. When the water becomes overheated, the heater’s auto shut off system kicks in and switches off power to the heater. The only way this can be overridden is by hitting the reset button behind the access panel on the heater.

A quick run to Lowes and back and about fifteen minutes to replace the fried thermostat was all it took for me to have the heater back online and in action.

Tuesday, July 31, 2007

Hate spending a fortune on passport photos?

It is not often that one needs passport photos, but when the need arises, it is usually arrives in the form of a deluge! Anyone who has had to file for the I485 or the N400 or Passports/Visa/PIO/OCI for the entire family knows what I am talking about. And those passport photos are not cheap either!

If you have had yours taken recently, you know how it works at the photo shops. They snap your photo using a digital camera and then hand it over to their photo software to do the rest. If you are a little bit enterprising, here is a cheap but efficient way of getting your passport photos.

Use your digital camera to take the photograph.
If you choose, you can use photo-editing software like Picasa (a free service) to refine the photo.
Then, use epassportphoto (also a free service) and follow the steps to upload your photograph, format to desired size and then save it back to your computer. Each image will be automatically sized to fit on a 4x6 paper and will have six to eight copies of your photograph depending on your chosen size. Copy this saved image onto your portable media and take it to a photo-printing lab to have it printed. If you are not able to use portable media, you can even choose a service like Snapfish (listed on the website) to have your photos printed at a neighborhood photo shop.

Alternatively, you can even print it at home provided you already have the required hardware. Once you have the printout, cut out the photographs and you are ready to put them to use! All this for the price (maybe lesser) of having a single 4x6 sheet printed.

Tuesday, July 24, 2007

GrandCentral - Manage your phones with one number!

Grand central has since been acquired by Google and is now called Google Voice.

Recently, I came across a telephone provider that had come up with an innovative approach of treating your phone number. GrandCentral operates on the simple concept that your phone number(s) should be tied to you, not the other way around!

What a neat concept! These days, most of us have at least three phone lines. Heck, some of us even have more phone lines than TV remote controls! How would it be if we can give out just one number to all of our contacts and that one number then manages the rest of our numbers? That way, regardless of the number of times our numbers may change, as long as the main number doesn't change, we don't have to communicate a number change ever again! That one main number is the number that you can now have from GrandCentral.

Once a GrandCentral (GCNumber) phone number is assigned to you, you can keep it for ever and you can link up all of your US numbers to your (US) GCNumber. Anybody calling your GCNumber will be forwarded to the (USA) numbers that you have asked your GCNumber to forward the call to. There are a host of other cool settings that can be setup right down to the individual contact level. You can record your conversation with a press of a button, have your voicemails forwarded in the form of emails, setup buttons on websites (like the one I have in the sidebar on this blog), transfer your call to another of your phones in the middle of your conversation and much much more.

Check out the demo that is posted on Tom's blog. For more information, goto the GrandCentral website or google 'grandcentral phone'.

Itching to check it out? Ever since Google purchased Grand Central early this month, signing up is by invitation only. I had been able to sign up thanks to Tom, and I now have a very few invites left. Just leave your full name and email Id. in a comment if you would like to be invited.

Thursday, December 29, 2005

De-interlacing and digital display units.

More and more people are taking a liking to digital TVs and digital display units. Needless to say, there are several factors that will need to be considered while shopping for the 'right' unit.

One of these factors is the de-interlacer that converts analog video signals to digital signals before the display unit can 'publish' them for our eyes. As we will be stuck with having to watch non-digital video for quite some time, we will have to remmeber that the digital set will have to be able to handle analog signals almost as well as it can handle digital feeds. This is where a good de-interlacer comes into the picture. One of the best de-interlacers in the market today happens to be DCDi by Faroudja which does a great job of converting analog feeds to digital feeds. I see this at work almost every day.

Other de-interlacers are available too, but it is always a good idea to check out how a display unit handles analog feeds before you decide to purchase the unit. Most shops will never feed the digital display units in the showroom with non-digital video (like regular, non-HD, cable/satellite video). So, be sure to ask for a demo so that you can compare both digital/regular video at work before deciding on that digital purchase.