Apr 21, 2014

Read the amount in vietnames words

 
    Dim so as String, dvchan as string, dvle As string, test as string


    
    IF {tbPaymentVoucher.CurrPay} = "VND" or {tbPaymentVoucher.CurrPay} = "JPY" THEN
         so = Trim(Cstr({tbPaymentVoucher.PayAmount},0))

    ELSE   
       so = Trim(Cstr({tbPaymentVoucher.PayAmount},2))
    END IF
   
    dvchan = " phẩy"

    IF {tbPaymentVoucher.CurrPay} = "VND" THEN
        dvle = "đồng"
    ELSE
        'dvle = " " & {tbInoivce.CurrName}
        dvle = "cent"
    END IF

    Dim Chu As String, solop As Number, numTmp As Double, tg As Double
    Dim ChuThapPhan as string
    Dim soNguyen As Double, soThapphan As Double
    Dim hangtram As Number, hangchuc As Number, hangdonvi As Number
    Dim vitriphay As Number
    Dim i As Number, index As Number
    Dim DOCCHUSO as string

    DOCCHUSO = ""
    Chu = ""

    If so = "" Then
        DOCCHUSO = ""
    End If
   
    'Kiểm tra số là số âm
    If CDbl(so) < 0 Then
        Chu = "âm "
        so = Trim(CStr(Abs(CDbl(so))))
    End If

    Dim term(3) as string
    ReDim term(10)
    Dim lop(8) As Double
    Dim  tlop(8) As String

    vitriphay = InStr(1, so, ".")
   
    If vitriphay > 0 Then
        soNguyen = CDbl(Mid(so, 1, vitriphay - 1))
        soThapphan = CDbl(Mid(so, vitriphay + 1))
'        if right(cstr(soThapphan),1)="0" then
   '         soThapphan = cdbl(left(cstr(soThapphan),1))
 '       end if
    Else
        soNguyen = CDbl(so)
        soThapphan = 0
    End If

   If soNguyen = 0 Then
        Chu = "Không"
    End If
    term(1) = " một"
    term(2) = " hai"
    term(3) = " ba"
    term(4) = " bốn"
    term(5) = " năm"
    term(6) = " sáu" 
    term(7) = " bảy"
    term(8) = " tám"
    term(9) = " chín"
    '-------------------
    tlop(1) = " "
    tlop(2) = " ngàn"
    tlop(3) = " triệu"
    tlop(4) = " tỉ"
    tlop(5) = " ngàn"
    tlop(6) = " triệu"
    tlop(7) = " tỉ"
    '----------------
    
'-----------------------
' doc tien so nguyen

  For index = 1 To 1
   If (soNguyen > 0) Then
    numTmp = soNguyen
    solop = 1
    Do While numTmp > 0
        tg = numTmp
        numTmp = Fix(numTmp / 1000)
        lop(solop) = tg - numTmp * 1000
        solop = solop + 1
    Loop
    i = solop - 1
    
    Do While i > 0
    numTmp = lop(i)
    If numTmp > 0 Then
        hangtram = Fix(numTmp / 100)
        hangchuc = Fix((numTmp - hangtram * 100) / 10)
        hangdonvi = numTmp - Fix(numTmp / 10) * 10
    If hangtram > 0 Then
    'Chu so hang tram c¢ nghªa numTmp>=100
        Chu = Chu + term(hangtram) + " trăm"
    Else
        If hangtram = 0 And (Right(Chu, 5) = " ngàn" ) And (hangchuc > 0 Or hangdonvi > 0) Then
            Chu = Chu + " không" & " trăm"
        End If
    End If
    'Xet chu so hang chuc
    If hangchuc > 1 Then
        Chu = Chu + term(hangchuc) + " mươi"
    ElseIf hangchuc = 1 Then
        Chu = Chu + " mười"
    ElseIf hangchuc = 0 And (Right(Chu, 5) = " trăm"  Or Right(Chu, 5) = " ngàn"  Or Right(Chu, 6) = " triệu" Or Right(Chu, 3) = " tỉ" ) And hangdonvi <> 0 Then
        Chu = Chu + " lẻ"
    End If
    ' Xet ch§ s– h…ng ­ón v«
    If hangdonvi = 1 And hangchuc > 1 Then
        Chu = Chu + " mốt" 
    ElseIf hangdonvi <> 5 And hangdonvi <> 0 Then
        Chu = Chu + term(hangdonvi)
    ElseIf hangdonvi = 5 And hangchuc <> 0 Then
        Chu = Chu + " lăm" 
    ElseIf hangdonvi = 5 And hangchuc = 0 Then
        Chu = Chu + " năm"
    End If
        Chu = Chu + tlop(i)
    End If
    ' Xet lop ke tiep
    i = i - 1
    Loop
    
   End If
   ' if (soNguyen > 1) then
         IF {tbPaymentVoucher.CurrPay} = "USD" then
             Chu = Trim(Chu) + " đô la Mỹ"
         elseif {tbPaymentVoucher.CurrPay} = "SGD" then
                Chu = Trim(Chu) + " đô la Sing"
              elseif {tbPaymentVoucher.CurrPay} = "JPY" then
                        Chu = Trim(Chu) + " yên"
           elseif {tbPaymentVoucher.CurrPay} = "VND" then
                        Chu = Trim(Chu) + " đồng"
            ELSE
                    Chu = Trim(Chu) + " "+{tbPaymentVoucher.CurrPay}
         end if
       
  '  elseif (soNguyen = 1) then
'        IF {tbLenhChuyenTien.CurrencyCode} = "USD" then
'             Chu = Trim(Chu) + " đô la Mỹ "
'        elseif {tbLenhChuyenTien.CurrencyCode} = "SGD" then
'                Chu = Trim(Chu) + " đô la Sing "
'              elseif {tbLenhChuyenTien.CurrencyCode} = "JPY" then
'                        Chu = Trim(Chu) + " yên "
'        end if
'    end if

    If index = 1 and (soThapphan <> 0) Then
        'Chu = Trim(Chu) & " " & dvchan
        Chu = Trim(Chu)
    End If
    'soNguyen = soThapphan
  Next
'-------------------------


'-------------------------
'' Doc so tien le thap phan
if (soThapphan <> 0) then
soNguyen = soThapphan

For index = 1 To 1
   If (soNguyen > 0) Then
    numTmp = soNguyen
    solop = 1
    Do While numTmp > 0
        tg = numTmp
        numTmp = Fix(numTmp / 1000)
        lop(solop) = tg - numTmp * 1000
        solop = solop + 1
    Loop
    i = solop - 1
    
    Do While i > 0
    numTmp = lop(i)
    If numTmp > 0 Then
        hangtram = Fix(numTmp / 100)
        hangchuc = Fix((numTmp - hangtram * 100) / 10)
        hangdonvi = numTmp - Fix(numTmp / 10) * 10
    If hangtram > 0 Then
    'Chu so hang tram c¢ nghªa numTmp>=100
        ChuThapPhan = ChuThapPhan + term(hangtram) + " trăm"
    Else
        If hangtram = 0 And (Right(ChuThapPhan, 5) = " ngàn" ) And (hangchuc > 0 Or hangdonvi > 0) Then
            ChuThapPhan = ChuThapPhan + " không" & " trăm"
        End If
    End If
    'Xet chu so hang chuc
    If hangchuc > 1 Then
        ChuThapPhan = ChuThapPhan + term(hangchuc) + " mươi"
    ElseIf hangchuc = 1 Then
        ChuThapPhan = ChuThapPhan + " mười"
    ElseIf hangchuc = 0 And (Right(ChuThapPhan, 5) = " trăm"  Or Right(ChuThapPhan, 5) = " ngàn"  Or Right(ChuThapPhan, 6) = " triệu" Or Right(ChuThapPhan, 3) = " tỉ" ) And hangdonvi <> 0 Then
        ChuThapPhan = ChuThapPhan + " lẻ"
    End If
    ' Xet ch§ s– h…ng ­ón v«
    If hangdonvi = 1 And hangchuc > 1 Then
        ChuThapPhan = ChuThapPhan + " mốt" 
    ElseIf hangdonvi <> 5 And hangdonvi <> 0 Then
        ChuThapPhan = ChuThapPhan + term(hangdonvi)
    ElseIf hangdonvi = 5 And hangchuc <> 0 Then
        ChuThapPhan = ChuThapPhan + " lăm" 
    ElseIf hangdonvi = 5 And hangchuc = 0 Then
        ChuThapPhan = ChuThapPhan + " năm"
    End If
        ChuThapPhan = ChuThapPhan + tlop(i)
    End If
    ' Xet lop ke tiep
    i = i - 1
    Loop
    
   End If
    if (soNguyen > 1) then
        ChuThapPhan = Trim(ChuThapPhan) + " cent"
    elseif (soNguyen = 1) then
        ChuThapPhan = Trim(ChuThapPhan) + " cent"
    end if   
  Next
end if
'-------------------------

    'If (vitriphay > 0) Then
        'Chu = Chu & lowercase({tbInoivce.CurrName}) & " phẩy " & dvle 
       ' Chu = Chu & dvle      
   ' else
       ' Chu = Chu & " " & dvle
    'End If
     IF {tbPaymentVoucher.CurrPay} = "VND" or {tbPaymentVoucher.CurrPay} = "JPY" THEN
        Chu = LTrim(Chu)
    ELSEIF  ChuThapPhan <> "" THEN
        Chu = LTrim(Chu) + " và " +ChuThapPhan
    ELSE
        Chu = LTrim(Chu)
    END IF
    If Chu <> "" Then
        Chu = UCase(Left(Chu, 1)) & Right(Chu, Len(Chu) - 1)
    End If

     DOCCHUSO = Chu
   
   formula = DOCCHUSO
 

0 comments:

Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib