VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Convert Number To Word

by OMKAR K. YADAV (4 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 19th August 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Convert Number To Word

Rate Convert Number To Word



  Dim rsword As String
  Dim Lword As String
  Dim Rword As String
  Dim paise As String
  rsword = "Rs  "
     rsvalue = Format(rsvalue, "0.00")
     SpcPos = InStr(1, rsvalue, ".")  ' Find space.
    If SpcPos Then
        Lword = Left(rsvalue, SpcPos - 1)    ' Get left word.
        Rword = Right(rsvalue, Len(rsvalue) - SpcPos) ' Get right word.
    
     End If
 Call convert(Lword, rsword)
 paise = ""
 If IsNumeric(Rword) Then
  x = Val(Rword)
  If x > 0 Then
     paise = " and paise "
    'rsword = rsword & "and paise"
  Call convert(Rword, paise)
    End If
  End If

     rsvalue = paise & " Only"
     Convert_In_Word = rsword & rsvalue
     
End Function

Sub convert(mleft As String, rsword As String)
Dim slength As Integer
Dim mi, mx As Integer
Dim mlakh As String
Dim mthousand As String
Dim mhund As String
Dim mten As String
Dim m As Integer
Dim s1, s2, Msg As String
Dim ml As Integer
Dim mth  As Integer
Dim mh As Integer
Dim mt As Integer
mlakh = ""
mthousand = ""
mhund = ""
mten = ""


slength = Len(mleft)
Select Case slength
       Case 1
             mt = Val(mleft)
             'Call convert0(mt, rsword)
       Case 2
              mten = mleft
              mt = Val(mten)
       Case 3
              mten = Right(mleft, 2)
              mhund = Left(mleft, 1)
              mt = Val(mten)
              mh = Val(mhund)
       
       Case 4
              mten = Right(mleft, 2)
              s1 = Left(mleft, 2)
              mhund = Right(s1, 1)
              mthousand = Left(s1, 1)
              mt = Val(mten)
              mh = Val(mhund)
              mth = Val(mthousand)
       Case 5
              mten = Right(mleft, 2)
              s1 = Left(mleft, 3)
              mhund = Right(s1, 1)
              mthousand = Left(s1, 2)
              mt = Val(mten)
              mh = Val(mhund)
              mth = Val(mthousand)

       Case 6
              mten = Right(mleft, 2)
              s1 = Left(mleft, 4)
              mhund = Right(s1, 1)
              s2 = Left(s1, 3)
              mthousand = Right(s2, 2)
              mlakh = Left(s2, 1)
              mt = Val(mten)
              mh = Val(mhund)
              mth = Val(mthousand)
              ml = Val(mlakh)

       Case 7
              mten = Right(mleft, 2)
              s1 = Left(mleft, 5)
              mhund = Right(s1, 1)
              s2 = Left(s1, 4)
              mthousand = Right(s2, 2)
              mlakh = Left(s2, 2)
              mt = Val(mten)
              mh = Val(mhund)
              mth = Val(mthousand)
              ml = Val(mlakh)
              

Case Else   ' Must be something else.
                Msg = "You did enter value more then one crore"
            End Select
        
If ml > 0 And ml < 10 Then
   Call convert0(ml, rsword)
    rsword = rsword & "Lakh"
 Else
If ml > 0 Then
   Call convert2(mlakh, rsword)
    rsword = rsword & "Lakh"
 End If

 End If
 If mth > 0 And mth < 10 Then
    Call convert0(mth, rsword)
    rsword = rsword & " Thousand "
    Else
    If mth > 0 Then
    Call convert2(mthousand, rsword)
    rsword = rsword & " Thousand "
     
     End If
   End If
 If mh > 0 Then
    Call convert0(mh, rsword)
    rsword = rsword & " Hundred "
    
     
   End If
  If mt >= 10 Then
    
    Call convert2(mten, rsword)
     
   Else
   Call convert0(mt, rsword)
  End If
    
End Sub

Sub convert0(m_y As Integer, rsword As String)

Select Case m_y
    Case 1
         rsword = rsword & " One "
    Case 2
         rsword = rsword & " Two "
    Case 3
         rsword = rsword & " Three "
    Case 4
         rsword = rsword & " Four "
    Case 5
         rsword = rsword & " Five "
    Case 6
    rsword = rsword & " Six "
    Case 7
    rsword = rsword & " Seven "
    Case 8
    rsword = rsword & " Eight "
    Case 9
    rsword = rsword & " Nine "
    End Select
    
End Sub

Sub convert2(mten As String, rsword As String)

Dim m_x, m_y As Integer

m_x = Val(Left(mten, 1))

m_y = Val(Right(mten, 1))

Select Case m_x
    Case 0
        Call convert0(m_y, rsword)
    Case 1
        Call converteleven(m_y, rsword)
    Case 2
          
          rsword = rsword & " Twenty "
          
          Call convert0(m_y, rsword)
         
    Case 3
          rsword = rsword & " Thirty "
          Call convert0(m_y, rsword)

    Case 4
          rsword = rsword & " Fourty "
          Call convert0(m_y, rsword)

    Case 5
          rsword = rsword & " Fifty "
          Call convert0(m_y, rsword)

    Case 6
          rsword = rsword & " Sixty "
          Call convert0(m_y, rsword)

    Case 7
          rsword = rsword & " Seventy "
          Call convert0(m_y, rsword)

    Case 8
          rsword = rsword & " Eighty "
          Call convert0(m_y, rsword)
    Case 9
          rsword = rsword & " Ninty "
          Call convert0(m_y, rsword)
    End Select
     

End Sub

Sub converteleven(m_y As Integer, rsword As String)

Select Case m_y
   Case 0
         rsword = rsword & " Ten"
   Case 1
       rsword = rsword & "Eleven"
   Case 2
       rsword = rsword & " Twelve "

   Case 3
  rsword = rsword & " Thirteen "
   Case 4
  rsword = rsword & " Fourteen "
   Case 5
  rsword = rsword & " Fifteen "
   Case 6
  rsword = rsword & " Sixteen "
   Case 7
  rsword = rsword & " Senenteen "
   Case 8
  rsword = rsword & " Eighteen "
   Case 9
  rsword = rsword & " Ninteen "
   End Select


End Sub

'how to use
'Convert_in_word("100.50")




Download this snippet    Add to My Saved Code

Convert Number To Word Comments

No comments have been posted about Convert Number To Word. Why not be the first to post a comment about Convert Number To Word.

Post your comment

Subject:
Message:
0/1000 characters