Converting Numbers to Words – Shortest code in VB.Net

This is a sample code I wrote in VB.Net which can output any number to words. This is the best code you may find in the internet because it uses recursion, it is fast and uses less system resources.

I assume that you know VB.Net already. So, I am not going to explain the code line by line.

During form load it popupates the array “Arr( )”. After that, you just have to call NumToWords(<your_number_here>) and it will return a string as output.

You can use it in your software, use it as a macro in Excel or do whatever you want.

As any other code, it still has its limits. Please feel free to modify and edit code at your own risk.

Public Class Form1

    Dim Arr(100) As String

    Public Function NumToWords(ByVal Num As Long) As String

        Dim n As Long

        Dim s As String

        s = ""

        If Num = 0 Then

            NumToWords = "Zero"

            Exit Function

        End If

        n = Num

        If n >= 10000000 Then

            s = s & NumToWords(n \ 10000000) & " Crore "

            n = n Mod 10000000

        End If

        If n >= 100000 Then

            s = s & NumToWords(n \ 100000) & " Lakh "

            n = n Mod 100000

        End If

        If n >= 1000 Then

            s = s & NumToWords(n \ 1000) & " Thousand "

            n = n Mod 1000

        End If

        If n >= 100 Then

            s = s & Arr(n \ 100) & " Hundred "

            n = n Mod 100

        End If

        If n > 20 Then

            s = s & Arr((n \ 10) * 10) & " "

            n = n Mod 10

        End If

        If n <= 20 And n > 0 Then

            s = s & Arr(n)

        End If

        NumToWords = s

    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Arr(0) = "Zero"

        Arr(1) = "One"

        Arr(2) = "Two"

        Arr(3) = "Three"

        Arr(4) = "Four"

        Arr(5) = "Five"

        Arr(6) = "Six"

        Arr(7) = "Seven"

        Arr(8) = "Eight"

        Arr(9) = "Nine"

        Arr(10) = "Ten"

        Arr(11) = "Eleven"

        Arr(12) = "Twelve"

        Arr(13) = "Thirteen"

        Arr(14) = "Fourteen"

        Arr(15) = "Fifteen"

        Arr(16) = "Sixteen"

        Arr(17) = "Seventeen"

        Arr(18) = "Eighteen"

        Arr(19) = "Nineteen"

        Arr(20) = "Twenty"

        Arr(30) = "Thirty"

        Arr(40) = "Fourty"

        Arr(50) = "Fifty"

        Arr(60) = "Sixty"

        Arr(70) = "Seventy"

        Arr(80) = "Eighty"

        Arr(90) = "Ninety"

    End Sub

End Class

Problem of shortcuts and missing folders and files in the pendrives, memory cards or hard disks

Sometimes, one of the most annoying moments in the life is that you have just copied some files/folders from your friend’s computer to your pen drive/hard disk and when you just plug it in to your PC, that files are missing. Not only that, your other folders present in your device are also changed to shortcut icons. This is a typical case of virus infection where it tries to spread from one computer to another by means of removable storage. In this case, your friend’s computer is the source, your removable storage device is the media and your computer is the target.

In this type of situations, what most people naturally do is click on the shortcuts. What most of the people don’t know is that this one click is enough to infect the target computer with the same virus. If you are lucky enough, your antivirus will detect and block it before it can infect your computer. Even if your antivirus succeeds in removing the virus, your problem of “missing folders and shortcuts appearing out of nowhere” does not get solved.  How can you find a solution to this problem?

Now this is what inspired me to write this blog as most of people are bewildered as to what happened, what to do, etc. To solve this problem, we have to understand one basic thing. A folder has two very important attributes – ‘System’ and ‘Hidden’. To make a long story short, If both these attributes are activated simultaneously for a folder (which is what happened in our case), you can deactivate them only using DOS or by other software as there is no option to do so using windows GUI.

You can do it in DOS like this:

  1. Scan your pen drive with your updated antivirus and clean all the virus.
  2. Note down the drive letter of your pen drive.
  3. Go to Command Prompt by typing CMD in the START>Run and pressing ENTER
  4. Type ATTRIB -S -H drive-letter:\* /S /D (for e.g. if your drive letter is G, then it should be ATTRIB -S -H G:\* /S /D) and press ENTER key.
  5. After the process finishes, your folders must be visible. Now, open your pen drive and delete all the shortcuts. Delete any doubtful file you find.

OR

You can use this tool I created with VB for this sole purpose. Click the below link to download:
Unhider

Download

Download “Unhider” Unhider.zip – Downloaded 77 times – 5 KB