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