954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Number To Word

0
By Selva Ganapathy on May 30th, 2008 10:12 am

This code snippet convert Number to String in VB6. For instance input 100 will be return as Hundred, It converts upto Core....

Option Explicit
Public Function UnitString(ByVal Ind As Integer) As String
   Dim ToStr As Variant
   ToStr = Array("Zero", "One", "Two", "Three", "Four", "Five", _
                                                "Six", "Seven", "Eight", "Nine", "Ten", _
                                                "Eleven", "Tweleve", "Thirteen", "Fourteen", "Fifteen", _
                                                "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty")
   UnitString = ToStr(Ind)
End Function
Public Function TenString(ByVal Ind As Integer) As String
   Dim ToStr As Variant
   ToStr = Array("Ten", "Twenty", "Thirty", "Fourty", "Fifty", _
                 "Sixty", "Seventy", "Eighty", "Ninety" _
                 )
   TenString = ToStr(Ind)
End Function
Public Function PlaceString(ByVal Ind As Integer) As String
   Dim ToStr As Variant
   ToStr = Array("Unit", "Tenth", "Hundred", _
                  "Thousand", "Laksh", "Crore", _
                  "Hundred" _
                 )
   PlaceString = ToStr(Ind)

End Function

Public Function ToString(ByVal No As Long) As String
   Dim ToStr As String
   'Dim No As Long
   Dim Value As Long
   Dim Divisor As Long
   Dim i As Long
   
   Divisor = 1000000000
   
   '  Crore TenLak Lak TenThous | Thous | Hund Ten Unit
'   If No > Divisor Then
'      Dim Remin As Long
'      Remin = Int(No / Divisor)
'      ToStr = ToString(Remin)
'   End If
   
   
   i = 6
   Do While (No >= 1000)
      Value = Int(No / Divisor)
      No = No Mod Divisor
      Divisor = Int(Divisor / 100)
      If (Value <> 0) Then
         ToStr = ToStr & NumberToString100(Value) & " " & PlaceString(i) + " "
      End If
      i = i - 1
   Loop
      
   Value = Int(No / 100)
   No = No Mod 100
   
   If (Value <> 0) Then
      ToStr = ToStr & NumberToString100(Value) & " " & PlaceString(i) + " "
   End If
   i = i - 1
   
   If No <> 0 Then
      ToStr = ToStr & NumberToString100(No)
   End If
   ToString = Trim(ToStr)
   End Function
Private Function NumberToString100(ByVal No As Integer) As String
   Dim ToStr As String
   Dim Ten As Integer, Unit As Integer
   
   If (No <= 20) Then
      NumberToString100 = UnitString(No)
      Exit Function
   End If
   No = No Mod 100
   Ten = Int(No / 10)
   No = No Mod 10
   Unit = No
   If (Ten >= 2) Then
      ToStr = ToStr & " " & TenString(Ten - 1)
      If (Unit > 0) Then
         ToStr = ToStr & " " & UnitString(Unit)
      End If
   ElseIf (Ten > 0) Then
      ToStr = ToStr & " " & UnitString((Ten * 10) + Unit)
   ElseIf (Unit > 0) Then
      ToStr = ToStr & " " & UnitString(Unit)
   End If
   
   NumberToString100 = Trim(ToStr)
End Function
Usage and Example:
 In a Form
 private sub Form_Load()
     MsgBox ToString(10023)
 End Sub

i hope u can teach me the very basic codes of visual basic because it is our subject this coming opening of school...

i hope u can help me with my homeworks...

thnx...

marivic

skinny_1990
Newbie Poster
1 post since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

i dont know if u mind...but i can teach you what i know, just ask me.(i recently took a course in VB so....)
just ask me, the name is aj

a.j.
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 3
 

tanx a lot i learn from this

cyberzeph
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

hi.. can i ask something...


hmmm can u pls convert your number to word ..from vb to .net.. hmmm tnx.. using if else structure??

legs067
Newbie Poster
1 post since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

plsss give me some examples of database connect to visualbasic. . .about the sales or inventory that have a simple code. . plsssssss because this is my project. . . plssss help me

chal
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

So on start up form I have made introduced a button that call up another form in my project (visual basic2008) and the code are dim f as new form
f.show form2
So what I want to do now is to draw a shape in form 2 ,and the parameters of shape in form 2 should be entered on start form.

Keitselepe
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

thanks for the code man it was very helpful

SoftwarePaladin
Newbie Poster
3 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You