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 *****
6 Dim bDoUnLoad as Boolean
12 Dim ListString as String
13 Dim MarketListBoxControl as Object
15 MarketListBoxControl = DlgStartUp.GetControl(
"lstMarkets
")
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
& ")
"
23 ListString = ListString
& " (
" & sMarketplace
& " " & sMarket(i,
2)
& ")
"
25 MarketListBoxControl.AddItem(ListString, a)
29 MarketListBoxControl.SelectItemPos(GlobListIndex, True)
30 DlgStartUp.Title = sDepotCurrency
31 DlgStartUp.Model.cmdGoOn.DefaultButton = True
32 DlgStartUp.GetControl(
"lstMarkets
").SetFocus()
38 Sub EnableGoOnButton()
39 StartUpModel.cmdGoOn.Enabled = True
40 StartUpModel.cmdGoOn.DefaultButton = True
44 Sub CloseStartUpDialog()
45 DlgStartUp.EndExecute()
46 ' oDocument.Dispose()
57 Sub ChooseMarket(Optional aEvent)
59 Dim bIsDocLanguage as Boolean
60 Dim 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
66 Index = oInternetModel.Tag
68 oMarketModel = GetControlModel(oDocument.Sheets(
0),
"CmdHistory
")
69 sCurCurrency = sMarket(Index,
1)
71 HistoryChartSource = sMarket(Index,
4)
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"
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()
94 DlgStartUp.EndExecute()
99 Sub ConvertStylesCurrencies()
101 Dim aStyleFormat as Object
102 Dim StyleName as String
103 Dim bAddToList as Boolean
105 Dim 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)
114 SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
117 ProtectSheets(oSheets)
121 Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
122 Dim nFormatLanguage as Integer
123 Dim nFormatDecimals as Integer
124 Dim nFormatLeading as Integer
125 Dim bFormatLeading as Integer
126 Dim bFormatNegRed as Integer
127 Dim bFormatThousands as Integer
128 Dim aNewStr as String
129 Dim iNumberFormat as Long
130 Dim sSimpleStr as String
131 Dim nSimpleKey as Long
133 Dim 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
"
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)
156 If Err
<> 0 Then
163 Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
165 nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
167 nRetKey = oFormats.addNew( aFormatStr, oLocale )
168 If nRetKey = -
1 Then nRetKey =
0
170 Numberformat = nRetKey
174 Function CheckFormatType(oStyle as Object)
175 Dim oFormatofObject as Object
176 oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
177 CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
178 End Function
</script:module>