Results 1 to 15 of 15

Thread: [RESOLVED] format currency to Indian format in Label/Textbox

Threaded View

  1. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: format currency to Indian format in Label/Textbox

    Code:
    Option Explicit
    
    Public Function FormatIndian(ByVal Amount As Currency) As String   
    Dim strAmount As String
    Dim strGrpsArr() As String
    Dim lngPos As Long
    Dim lngIndex As Long
    
       strAmount = Format$(Amount, "#") 'note: rounding occurs
       If Len(strAmount) < 4 Then
          FormatIndian = strAmount
       Else
          lngIndex = (Len(strAmount) - 2) \ 2
          ReDim strGrpsArr(lngIndex)
          
          strGrpsArr(lngIndex) = Mid$(strAmount, Len(strAmount) - 2)  'least significant trio
          
          lngPos = Len(strAmount) - 4:  lngIndex = lngIndex - 1       'init position variables
          Do
             strGrpsArr(lngIndex) = Mid$(strAmount, lngPos, 2)
             lngPos = lngPos - 2:       lngIndex = lngIndex - 1       'update variables
             If lngPos = 0 Then strGrpsArr(0) = Left$(strAmount, 1)   'leading non-pair group
          Loop Until lngPos <= 0
          
          FormatIndian = Join(strGrpsArr, ",")
          Erase strGrpsArr
       End If
    End Function
    
    Private Sub Form_Load()
    Dim curTest As Currency
    
       curTest = 4456456456716#
       Debug.Print FormatIndian(curTest)
    End Sub
    Me.lblAmt.Caption = FormatIndian(rsCurrent.Fields("suitAmount").Value)
    Last edited by leinad31; Feb 27th, 2007 at 07:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width