Advertisement
Guest User

Untitled

a guest
Oct 8th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Option Compare Text
  3.  
  4. Dim eh$(99)
  5. Dim vv$(12)
  6.  
  7. Function getaltekst(getal As Variant) As String
  8. Dim heel, deel 'decimal variants
  9. Dim txt$, n% 'string/int
  10. vulArrays
  11. heel = Int(CDec(Abs(getal)))
  12. deel = CDec(Abs(getal)) - heel
  13.  
  14. txt = IIf(Sgn(getal) < 0, "min ", "") & _
  15. IIf(heel = 0, IIf(deel = 0, "nul", ""), spel(heel))
  16.  
  17. If deel <> 0 Then
  18. txt = txt & IIf(heel = 0, "", " en ")
  19. n = Len(Mid(deel, 3))
  20. 'boven miljoenste per macht van 3
  21. n = n + IIf(n < 6, 0, (3 - n Mod 3) Mod 3)
  22. deel = deel * (10 ^ n)
  23. txt = txt & spel(deel) & " " & _
  24. Trim(Replace(spel(10 ^ n), "een", "")) & _
  25. IIf(n = 1, "de", "ste")
  26. End If
  27.  
  28. getaltekst = txt
  29. End Function
  30.  
  31. Function spel$(n)
  32. Dim t$, tmp$, b$, b1$, b2$
  33. Dim i%, s%, hv%, dv%
  34.  
  35. t = CStr(n)
  36. 'blokje van 4 bij getal tm 9999
  37. s = IIf(Len(t) = 4, 4, 3)
  38. 'met nullen vullen tot lengte een veelvoud is van 3
  39. t = String((s - Len(t) Mod s) Mod s, "0") & t
  40.  
  41. For i = 1 To Len(t) Step s
  42. tmp = Mid(t, i, s)
  43. b1 = Left(tmp, Len(tmp) - 2)
  44. hv = IIf(Right(b1, 1) = 0, 3, 2) 'duizend/honderd
  45. b1 = IIf(Right(b1, 1) = 0, Left(b1, 1), b1) 'idem
  46.  
  47. b1 = xx(b1)
  48. b1 = IIf(b1 = "een", " ", b1) 'geen eenhonderd
  49. b1 = b1 & IIf(b1 = "", "", vv(hv)) 'plak veelvoud
  50.  
  51. b2 = Right(tmp, 2)
  52. dv = Len(t) - i - (s - 1) 'duizendvoud
  53. b2 = xx(b2)
  54.  
  55. 'spatiëring
  56. 'optioneel EN voor getal tm 12
  57. b2 = IIf(dv = 0 And b1 <> "" And _
  58. Right(tmp, 2) > 0 And Right(tmp, 2) <= 12, _
  59. "en " & b2, b2)
  60. b = Trim(b1 & " " & b2) & " "
  61. 'geen spatie veelvoud duizend hfdtelwoord tm honderd
  62. If (dv = 3 And Right(tmp, 2) = "00") Then b = Trim(b)
  63. 'geen spatie veelvoud honderd
  64. If (dv = 3 And tmp < 100) Then b = Trim(b)
  65.  
  66. spel = Trim(spel & " " & b & IIf(tmp = "000", "", vv(dv)))
  67. Next
  68. End Function
  69.  
  70. Private Function xx$(n$)
  71. 'spelt tm 99
  72. If eh(n) <> "" Then
  73. xx = eh(n)
  74. Else
  75. xx = eh(Right(n, 1)) & _
  76. IIf(Left(n, 1) = 1 Or Right(n, 1) = 0, "", _
  77. IIf(Right(xx, 1) = "e", "ën", "en")) & _
  78. IIf(eh(Left(n, 1) * 10) <> "", eh(Left(n, 1) * 10), _
  79. eh(Left(n, 1)) & vv(1))
  80. End If
  81. xx = Trim(xx)
  82. End Function
  83.  
  84. Private Sub vulArrays()
  85. eh(0) = " "
  86. eh(1) = "een"
  87. eh(2) = "twee"
  88. eh(3) = "drie"
  89. eh(4) = "vier"
  90. eh(5) = "vijf"
  91. eh(6) = "zes"
  92. eh(7) = "zeven"
  93. eh(8) = "acht"
  94. eh(9) = "negen"
  95. eh(10) = "tien"
  96. eh(11) = "elf"
  97. eh(12) = "twaalf"
  98. eh(13) = "dertien"
  99. eh(14) = "veertien"
  100. eh(20) = "twintig"
  101. eh(30) = "dertig"
  102. eh(40) = "veertig"
  103. eh(80) = "tachtig"
  104. vv(1) = "tig"
  105. vv(2) = "honderd"
  106. vv(3) = "duizend"
  107. vv(6) = "miljoen"
  108. vv(9) = "miljard"
  109. vv(12) = "biljoen"
  110. End Sub
  111.  
  112.  
  113. '**********************************************************
  114. ' Conditional compilation of Replace Function for xl97
  115. '**********************************************************
  116.  
  117. #If VBA6 Then
  118. 'use standard replace
  119. #Else
  120. Private Function Replace( _
  121. sText As String, sFind As String, sRepl As String, _
  122. Optional Start As Long = 1, Optional Count As Long = 1, _
  123. Optional Compare As Long = vbTextCompare) As String
  124.  
  125. Dim n%, m%
  126. If sText = "" Then
  127. Replace = ""
  128. Else
  129. n = InStr(1, sText, sFind, Compare)
  130. Do While n > 0
  131. sText = Left(sText, n - 1) _
  132. & sRepl & Mid(sText, n + Len(sFind), Len(sText) - n -
  133. Len(sFind) + 1)
  134. n = InStr(n, sText, sFind)
  135. Loop
  136. Replace = sText
  137. End If
  138. End Function
  139. #End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement