Currency.xba 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--
  4. * This file is part of the LibreOffice project.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  12. * Licensed to the Apache Software Foundation (ASF) under one or more
  13. * contributor license agreements. See the NOTICE file distributed
  14. * with this work for additional information regarding copyright
  15. * ownership. The ASF licenses this file to you under the Apache
  16. * License, Version 2.0 (the "License"); you may not use this file
  17. * except in compliance with the License. You may obtain a copy of
  18. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  19. -->
  20. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Currency" script:language="StarBasic">REM ***** BASIC *****
  21. Option Explicit
  22. Dim bDoUnLoad as Boolean
  23. Sub Startup()
  24. Dim i as Integer
  25. Dim a as Integer
  26. Dim ListString as String
  27. Dim MarketListBoxControl as Object
  28. Initialize(False)
  29. MarketListBoxControl = DlgStartUp.GetControl(&quot;lstMarkets&quot;)
  30. a = 0
  31. For i = 0 To Ubound(sMarket(),1)
  32. ListString = sMarket(i,0)
  33. If sMarket(i,0) &lt;&gt; &quot;&quot; Then
  34. If sMarket(i,3) = &quot;&quot; Then
  35. ListString = ListString &amp; &quot; (&quot; &amp; sNoInternetUpdate &amp; &quot;)&quot;
  36. Else
  37. ListString = ListString &amp; &quot; (&quot; &amp; sMarketplace &amp; &quot; &quot; &amp; sMarket(i,2) &amp; &quot;)&quot;
  38. End If
  39. MarketListBoxControl.AddItem(ListString, a)
  40. a = a + 1
  41. End If
  42. Next i
  43. MarketListBoxControl.SelectItemPos(GlobListIndex, True)
  44. DlgStartUp.Title = sDepotCurrency
  45. DlgStartUp.Model.cmdGoOn.DefaultButton = True
  46. DlgStartUp.GetControl(&quot;lstMarkets&quot;).SetFocus()
  47. DlgStartUp.Execute()
  48. DlgStartUp.Dispose()
  49. End Sub
  50. Sub EnableGoOnButton()
  51. StartUpModel.cmdGoOn.Enabled = True
  52. StartUpModel.cmdGoOn.DefaultButton = True
  53. End Sub
  54. Sub CloseStartUpDialog()
  55. DlgStartUp.EndExecute()
  56. &apos; oDocument.Dispose()
  57. End Sub
  58. Sub DisposeDocument()
  59. If bDoUnload Then
  60. oDocument.Dispose()
  61. End If
  62. End Sub
  63. Sub ChooseMarket(Optional aEvent)
  64. Dim Index as Integer
  65. Dim bIsDocLanguage as Boolean
  66. Dim bIsDocCountry as Boolean
  67. oInternetModel = GetControlModel(oDocument.Sheets(0), &quot;CmdInternet&quot;)
  68. If Not IsMissing(aEvent) Then
  69. Index = StartupModel.lstMarkets.SelectedItems(0)
  70. oInternetModel.Tag = Index
  71. Else
  72. Index = oInternetModel.Tag
  73. End If
  74. oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
  75. sCurCurrency = sMarket(Index,1)
  76. If Index = 0 Then
  77. HistoryChartSource = sMarket(Index,4)
  78. End If
  79. sCurStockIDLabel = sMarket(Index,5)
  80. sCurExtension = sMarket(Index,8)
  81. iValueCol = Val(sMarket(Index,10))
  82. If Instr(sCurExtension,&quot;;&quot;) &lt;&gt; 0 Then
  83. &apos; Take the german extension as the stock place is Frankfurt
  84. sCurExtension = &quot;407&quot;
  85. End If
  86. sCurChartSource = sMarket(Index,3)
  87. bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) &lt;&gt; 0
  88. bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) &lt;&gt; 0 OR SDocCountry = &quot;&quot;
  89. sCurSeparator = sMarket(Index,9)
  90. TransactModel.txtRate.CurrencySymbol = sCurCurrency
  91. TransactModel.txtFix.CurrencySymbol = sCurCurrency
  92. TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
  93. bEnableMarket = Index = 0
  94. bEnableInternet = sCurChartSource &lt;&gt; &quot;&quot;
  95. oMarketModel.Enabled = bEnableMarket
  96. oInternetModel.Enabled = bEnableInternet
  97. If Not IsMissing(aEvent) Then
  98. ConvertStylesCurrencies()
  99. bDoUnload = False
  100. DlgStartUp.EndExecute()
  101. End If
  102. End Sub
  103. Sub ConvertStylesCurrencies()
  104. Dim m as integer
  105. Dim aStyleFormat as Object
  106. Dim StyleName as String
  107. Dim bAddToList as Boolean
  108. Dim oStyle as Object
  109. Dim oStyles as Object
  110. UnprotectSheets(oSheets)
  111. oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
  112. oStyles = oDocument.StyleFamilies.GetbyIndex(0)
  113. For m = 0 To oStyles.count-1
  114. oStyle = oStyles.GetbyIndex(m)
  115. StyleName = oStyle.Name
  116. bAddToList = CheckFormatType(oStyle)
  117. If bAddToList Then
  118. SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
  119. End If
  120. Next m
  121. ProtectSheets(oSheets)
  122. End Sub
  123. Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
  124. Dim nFormatLanguage as Integer
  125. Dim nFormatDecimals as Integer
  126. Dim nFormatLeading as Integer
  127. Dim bFormatLeading as Integer
  128. Dim bFormatNegRed as Integer
  129. Dim bFormatThousands as Integer
  130. Dim aNewStr as String
  131. Dim iNumberFormat as Long
  132. Dim sSimpleStr as String
  133. Dim nSimpleKey as Long
  134. Dim aFormat()
  135. Dim oLocale as New com.sun.star.lang.Locale
  136. &apos; Numberformat with the new Symbol as Base for new Format
  137. sSimpleStr = &quot;0 [$&quot; &amp; sNewSymbol &amp; &quot;-&quot; &amp; sNewExtension &amp; &quot;]&quot;
  138. nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
  139. On Local Error Resume Next
  140. iNumberFormat = oObject.NumberFormat
  141. If Err &lt;&gt; 0 Then
  142. Msgbox &quot;Error Reading the Number Format&quot;
  143. Resume CLERROR
  144. End If
  145. On Local Error GoTo NOKEY
  146. aFormat() = oFormats.getByKey(iNumberFormat)
  147. On Local Error GoTo 0
  148. &apos; set new currency format with according settings
  149. nFormatDecimals = aFormat.Decimals
  150. nFormatLeading = aFormat.LeadingZeros
  151. bFormatNegRed = aFormat.NegativeRed
  152. bFormatThousands = aFormat.ThousandsSeparator
  153. oLocale = aFormat.Locale
  154. aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
  155. oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
  156. NOKEY:
  157. If Err &lt;&gt; 0 Then
  158. Resume CLERROR
  159. End If
  160. CLERROR:
  161. End Sub
  162. Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
  163. Dim nRetkey
  164. nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
  165. If nRetKey = -1 Then
  166. nRetKey = oFormats.addNew( aFormatStr, oLocale )
  167. If nRetKey = -1 Then nRetKey = 0
  168. End If
  169. Numberformat = nRetKey
  170. End Function
  171. Function CheckFormatType(oStyle as Object)
  172. Dim oFormatofObject as Object
  173. oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
  174. CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
  175. End Function</script:module>