Prikazi cijelu temu 28.10.2016 19:10
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Lokacija:zagreb


Predmet:test vba kod
PreuzmiIzvorni kôd (Visual Basic):
  1. Function BrSlovima(Broj) As String
  2. '******************************************
  3. 'Ime:     BrSlovima Function
  4. 'Sadržaj: ispisuje broj tekstom
  5. 'Autor:     ZXZ
  6. 'Datum:      08 16, 2009, 12:34:16
  7. 'Adresa: Tuzla BiH
  8. 'Email:     izonic@inet.ba
  9. 'Ulazni parametri:broj
  10. 'Izlazni parametri:broj ispisan tekstom
  11. '*****************************************
  12. Dim I1 As Integer, I2 As Integer
  13. Dim N1 As Integer, N2 As Integer
  14. Dim DioTri As String
  15. Dim MjestoTri As Integer
  16. Dim RodJ As Integer
  17. Dim Strb As String
  18. Dim Cifra As Integer
  19. Dim Str(1 To 2) As String
  20.  
  21. 'Broj = 112
  22.  
  23. N1 = Fix(Len(Format$(Broj)) / 3)
  24. If Len(Format$(Broj)) Mod 3 > 0 Then
  25. N1 = N1 + 1
  26. End If
  27. For I1 = 1 To N1
  28.         If I1 = 3 Then
  29.         RodJ = 1
  30. Else
  31.         RodJ = 2
  32. End If
  33.  
  34. If I1 = N1 Then
  35.         MjestoTri = 1
  36.         N2 = Len(Format$(Broj)) Mod 3
  37.         If N2 = 0 Then: N2 = 3
  38.         Else
  39.                 N2 = 3
  40.                 MjestoTri = Len(Format$(Broj)) - I1 * 3 + 1
  41.         End If
  42.    
  43.         DioTri = Mid(Format$(Broj), MjestoTri, N2)
  44.         For I2 = 1 To N2
  45.                 Cifra = Mid(DioTri, N2 - I2 + 1, 1)
  46.                 If Cifra = 1 And Strb = "etiri" Then
  47.                         Strb = "etr"
  48.                 End If
  49.                 If Cifra = 1 And Strb = "Å¡est" Then
  50.                         Strb = "Å¡es"
  51.                 End If
  52.                 Str(1) = Cifre(Cifra, I2, I1)
  53.                 If Str(1) = "naest" And Str(2) = "jedan" Then
  54.                         Str(1) = "aest"
  55.                 End If
  56.                 If Str(1) = "nula" Then GoTo Petlja
  57.                 If Cifra = 1 And I2 = 2 Then
  58.                 If Str(2) = "nula" Then Str(1) = "deset"
  59.                         Strb = Strb & Str(1)
  60.                 Else
  61.                         Strb = Str(1) & Strb
  62.                 End If
  63.                 Petlja:
  64.                 Str(2) = Str(1)
  65.         Next I2
  66.    
  67.         BrSlovima = Strb & ImenaB(DioTri, RodJ, I1) & BrSlovima
  68.         Strb = ""
  69. Next I1
  70. End Function
  71.  
  72. Function Cifre(Cifra As Integer, PoRedu As Integer, Rod As Integer) As String
  73.  
  74. Select Case Cifra
  75.  
  76. Case 0
  77.         Cifre = "nula"
  78.         GoTo Kraj
  79. Case 1
  80.         If PoRedu = 1 Then
  81.                 If Rod = 1 Or Rod = 3 Or Rod = 5 Then
  82.                         Cifre = "jedan"
  83.                 Else
  84.                         Cifre = "jedna"
  85.                 End If
  86.         ElseIf PoRedu = 2 Then
  87.                 Cifre = "jeda"
  88.         End If
  89. Case 2
  90.         If PoRedu = 1 Or PoRedu = 3 Then
  91.                 If Rod = 1 Or Rod = 3 Or Rod = 5 Then
  92.                         Cifre = "dva"
  93.                 Else
  94.                         Cifre = "dvije"
  95.                 End If
  96.         ElseIf PoRedu = 2 Then
  97.                         Cifre = "dva"
  98.         End If
  99. Case 3
  100.         Cifre = "tri"
  101. Case 4
  102.         If PoRedu = 1 Or PoRedu = 3 Then
  103.                 Cifre = "etiri"
  104.         Else
  105.                 Cifre = "etr"
  106.         End If
  107. Case 5
  108.         If PoRedu = 2 Then
  109.                 Cifre = "pe"
  110.         Else
  111.                 Cifre = "pet"
  112.         End If
  113. Case 6
  114.         If PoRedu = 2 Then
  115.                 Cifre = "Å¡ez"
  116.         Else
  117.                 Cifre = "Å¡est"
  118.         End If
  119. Case 7
  120.         Cifre = "sedam"
  121. Case 8
  122.         Cifre = "osam"
  123. Case 9
  124.         If PoRedu = 2 Then
  125.                 Cifre = "deve"
  126.         Else
  127.                 Cifre = "devet"
  128.         End If
  129. End Select
  130. If PoRedu = 2 Then
  131.         If Cifra = 1 Then
  132.                 Cifre = "naest"
  133.         Else
  134.                 Cifre = Cifre & "deset"
  135.         End If
  136. ElseIf PoRedu = 3 Then
  137.         If Cifra = 2 Or Cifra = 3 Or Cifra = 4 Then
  138.                 Cifre = Cifre & "stotine"
  139.         ElseIf Cifra = 1 Then
  140.                 Cifre = "stotinu"
  141.         ElseIf Cifra = 0 Then
  142.         Else
  143.                 Cifre = Cifre & "stotina"
  144.         End If
  145. End If
  146. Kraj:
  147. End Function
  148.  
  149.  
  150. Function ImenaB(StrBr As String, Rod As Integer, PoRedu) As String
  151. Dim Cifra As Integer
  152. Dim Druga As Integer
  153.  
  154. If Val(StrBr) = 0 Then GoTo Kraj
  155. Cifra = Val(Right(StrBr, 1))
  156. If Len(StrBr) > 1 Then
  157. Druga = Val(Mid(StrBr, Len(StrBr) - 1, 1))
  158. End If
  159.  
  160. Select Case PoRedu
  161.  
  162. Case 1
  163. 'ništa
  164. Case 2
  165.         If Cifra = 2 Or Cifra = 3 Or Cifra = 4 Then
  166.                 If Druga = 1 Then
  167.                         ImenaB = "hiljada"
  168.                 Else
  169.                         ImenaB = "hiljade"
  170.                 End If
  171.         Else
  172.                 ImenaB = "hiljada"
  173.         End If
  174. Case 3
  175.         If Cifra = 1 Then
  176.                 If Druga = 1 Then
  177.                         ImenaB = "miliona"
  178.                 Else
  179.                         ImenaB = "milion"
  180.                 End If
  181.         Else
  182.                 ImenaB = "miliona"
  183.         End If
  184. Case 4
  185.         If Cifra = 2 Or Cifra = 3 Or Cifra = 4 Then
  186.                 If Druga = 1 Then
  187.                         ImenaB = "milijardi"
  188.                 Else
  189.                         ImenaB = "milijarde"
  190.                 End If
  191.         ElseIf Cifra = 1 Then
  192.                 If Druga = 1 Then
  193.                         ImenaB = "milijardi"
  194.                 Else
  195.                         ImenaB = "milijarda"
  196.                 End If
  197.         Else
  198.                 ImenaB = "milijardi"
  199.         End If
  200. Case 5
  201.         End Select
  202. Kraj:
  203. End Function
  204. '*--------------------------------------broj slovima kraj-------------------------------------------------

zivot je moja domovina.