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
8
Contributors
7
Replies
13
Views
8 Years
Discussion Span
Last Post by SoftwarePaladin
-1

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

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....)
<i> just ask me, the name is aj</i>

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??

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

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.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.