Tema: Re: kaina excelyje Lt->eur
Autorius: Linas Petkeviius
Data: 2015-02-02 14:43:50
Public Function Suma_EUR(ByVal Suma) As String
Dim minus As String

If IsNull(Suma) Or Suma = 0 Then
Suma_EUR = ""
 Exit Function
End If

If Suma < 0 Then
Suma = Abs(Suma)
minus = "minus "
Else
minus = ""
End If

Dim ct$, X, Mase, MasesSuma, Liko, i, Liet$, Linksnis, Pirma$, Kitos$


Static Pinigai$(3, 3)
    Pinigai$(1, 1) = "euras"
    Pinigai$(1, 2) = "eurai"
    Pinigai$(1, 3) = "eur"
    Pinigai$(2, 1) = "tkstantis"
    Pinigai$(2, 2) = "tkstaniai"
    Pinigai$(2, 3) = "tkstani"
    Pinigai$(3, 1) = "milijonas"
    Pinigai$(3, 2) = "milijonai"
    Pinigai$(3, 3) = "milijon"
Static M(3)
    M(1) = 1
    M(2) = 1000
    M(3) = 1000000

Const Max_sk = 36     'Masyvo element skaiius
Static SkaiciaiN(36)
    SkaiciaiN(1) = 1
    SkaiciaiN(2) = 2
    SkaiciaiN(3) = 3
    SkaiciaiN(4) = 4
    SkaiciaiN(5) = 5
    SkaiciaiN(6) = 6
    SkaiciaiN(7) = 7
    SkaiciaiN(8) = 8
    SkaiciaiN(9) = 9
    SkaiciaiN(10) = 10
    SkaiciaiN(11) = 11
    SkaiciaiN(12) = 12
    SkaiciaiN(13) = 13
    SkaiciaiN(14) = 14
    SkaiciaiN(15) = 15
    SkaiciaiN(16) = 16
    SkaiciaiN(17) = 17
    SkaiciaiN(18) = 18
    SkaiciaiN(19) = 19
    SkaiciaiN(20) = 20
    SkaiciaiN(21) = 30
    SkaiciaiN(22) = 40
    SkaiciaiN(23) = 50
    SkaiciaiN(24) = 60
    SkaiciaiN(25) = 70
    SkaiciaiN(26) = 80
    SkaiciaiN(27) = 90
    SkaiciaiN(28) = 100
    SkaiciaiN(29) = 200
    SkaiciaiN(30) = 300
    SkaiciaiN(31) = 400
    SkaiciaiN(32) = 500
    SkaiciaiN(33) = 600
    SkaiciaiN(34) = 700
    SkaiciaiN(35) = 800
    SkaiciaiN(36) = 900

Static SkaiciaiS$(36)
    SkaiciaiS$(1) = "vienas"
    SkaiciaiS$(2) = "du"
    SkaiciaiS$(3) = "trys"
    SkaiciaiS$(4) = "keturi"
    SkaiciaiS$(5) = "penki"
    SkaiciaiS$(6) = "ei"
    SkaiciaiS$(7) = "septyni"
    SkaiciaiS$(8) = "atuoni"
    SkaiciaiS$(9) = "devyni"
    SkaiciaiS$(10) = "deimt"
    SkaiciaiS$(11) = "vienuolika"
    SkaiciaiS$(12) = "dvylika"
    SkaiciaiS$(13) = "trylika"
    SkaiciaiS$(14) = "keturiolika"
    SkaiciaiS$(15) = "penkiolika"
    SkaiciaiS$(16) = "eiolika"
    SkaiciaiS$(17) = "septyniolika"
    SkaiciaiS$(18) = "atuoniolika"
    SkaiciaiS$(19) = "devyniolika"
    SkaiciaiS$(20) = "dvideimt"
    SkaiciaiS$(21) = "trisdeimt"
    SkaiciaiS$(22) = "keturiasdeimt"
    SkaiciaiS$(23) = "penkiasdeimt"
    SkaiciaiS$(24) = "eiasdeimt"
    SkaiciaiS$(25) = "septyniasdeimt"
    SkaiciaiS$(26) = "atuoniasdeimt"
    SkaiciaiS$(27) = "devyniasdeimt"
    SkaiciaiS$(28) = "vienas imtas"
    SkaiciaiS$(29) = "du imtai"
    SkaiciaiS$(30) = "trys imtai"
    SkaiciaiS$(31) = "keturi imtai"
    SkaiciaiS$(32) = "penki imtai"
    SkaiciaiS$(33) = "ei imtai"
    SkaiciaiS$(34) = "septyni imtai"
    SkaiciaiS$(35) = "atuoni imtai"
    SkaiciaiS$(36) = "devyni imtai"

Static SkaiciaiL(36)
    SkaiciaiL(1) = 1
    SkaiciaiL(2) = 2
    SkaiciaiL(3) = 2
    SkaiciaiL(4) = 2
    SkaiciaiL(5) = 2
    SkaiciaiL(6) = 2
    SkaiciaiL(7) = 2
    SkaiciaiL(8) = 2
    SkaiciaiL(9) = 2
    SkaiciaiL(10) = 3
    SkaiciaiL(11) = 3
    SkaiciaiL(12) = 3
    SkaiciaiL(13) = 3
    SkaiciaiL(14) = 3
    SkaiciaiL(15) = 3
    SkaiciaiL(16) = 3
    SkaiciaiL(17) = 3
    SkaiciaiL(18) = 3
    SkaiciaiL(19) = 3
    SkaiciaiL(20) = 3
    SkaiciaiL(21) = 3
    SkaiciaiL(22) = 3
    SkaiciaiL(23) = 3
    SkaiciaiL(24) = 3
    SkaiciaiL(25) = 3
    SkaiciaiL(26) = 3
    SkaiciaiL(27) = 3
    SkaiciaiL(28) = 3
    SkaiciaiL(29) = 3
    SkaiciaiL(30) = 3
    SkaiciaiL(31) = 3
    SkaiciaiL(32) = 3
    SkaiciaiL(33) = 3
    SkaiciaiL(34) = 3
    SkaiciaiL(35) = 3
    SkaiciaiL(36) = 3

    'Tuojau pat iskirsime centus
    ct$ = Right(Format(Suma, "0.00"), 2)
    For X = 3 To 1 Step -1
    Mase = M(X)                     ' k skaiiuosime: milijonus,
tkstanius, litus
    MasesSuma = Int(Suma / Mase)    ' tai tiek t milijun
    Liko = Suma - MasesSuma * Mase  ' tiek dar liks sekaniam kartui
    Suma = MasesSuma
    If Suma > 0 Then                ' ar yra nors vienas milijonas?
        For i = Max_sk To 1 Step -1                             ' teks
pereiti per vis masyv
            If Suma >= SkaiciaiN(i) Then                    ' gal jau tas
skaiius
                Liet$ = Liet$ + SkaiciaiS$(i) + " "     ' prijungsim jo
pavadinim
                Linksnis = SkaiciaiL(i)                 ' siminsim jo
linksn
                Suma = Suma - SkaiciaiN(i)              ' ir imesim j i
galvos
            End If
        Next i
        Liet$ = Liet$ + Pinigai$(X, Linksnis) + " "     'nepamirkim pridti
milijono!
    End If
    Suma = Liko     'paskaiiuosim tai, k palikome sekaniam kartui
    Linksnis = 3    'dl visa ko galvosim apie  linksn
    Next X
    If MasesSuma = 0 Then Liet$ = Liet$ + "eur"    ' jei buvo gryni
milijonai arba tkstaniai,
                            ' reikia pridti odel LITAS
    'Cento tikslumu!
    Liet$ = Trim(Liet$) & " " & ct$ & " ct"

    'Pirma raid - didioji
    Pirma$ = UCase$(Left$(Liet$, 1))
    Kitos$ = Right$(Liet$, (Len(Liet$) - 1))
    Suma_EUR = minus + Pirma$ + Kitos$

    End Function