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=
"tools" script:
language=
"StarBasic">REM ***** BASIC *****
7 If oSheets.HasbyName(
"Link
") then
8 oSheets.RemovebyName(
"Link
")
13 Sub InitializeStatusLine(StatusText as String, MaxValue as Integer, FirstValue as Integer)
14 oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
15 oStatusLine.Start(StatusText, MaxValue)
16 oStatusline.SetValue(FirstValue)
20 Sub MakeRangeVisible(oSheet as Object, RangeName as String, BIsVisible as Boolean)
21 Dim oRangeAddress, oColumns as Object
22 Dim i, iStartColumn, iEndColumn as Integer
23 oRangeAddress = oSheet.GetCellRangeByName(RangeName).RangeAddress
24 iStartColumn = oRangeAddress.StartColumn
25 iEndColumn = oRangeAddress.EndColumn
26 oColumns = oSheet.Columns
27 For i = iStartColumn To iEndColumn
28 oSheet.Columns(i).IsVisible = bIsVisible
33 Function GetRowIndex(oSheet as Object, RowName as String)
35 oRange = oSheet.GetCellRangeByName(RowName)
36 GetRowIndex = oRange.RangeAddress.StartRow
40 Function GetTransactionCount(iStartRow as Integer)
41 Dim iEndRow as Integer
42 iStartRow = GetRowIndex(oMovementSheet,
"ColumnsToHide
")
43 iEndRow = GetRowIndex(oMovementSheet,
"HiddenRow3
" )
44 GetTransactionCount = iEndRow -iStartRow -
2
48 Function GetStocksCount(iStartRow as Integer)
49 Dim iEndRow as Integer
50 iStartRow = GetRowIndex(oFirstSheet,
"HiddenRow1
")
51 iEndRow = GetRowIndex(oFirstSheet,
"HiddenRow2
")
52 GetStocksCount = iEndRow -iStartRow -
1
56 Function FillListbox(ListboxControl as Object, MsgTitle as String, bShowMessage) as Boolean
57 Dim i, StocksCount as Integer
58 Dim iStartRow as Integer
60 ' Add stock names to empty list box
61 StocksCount = GetStocksCount(iStartRow)
62 If StocksCount
> 0 Then
63 ListboxControl.Model.StringItemList() = NullList()
64 For i =
1 To StocksCount
65 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
66 ListboxControl.AddItem(oCell.String, i-
1)
71 Msgbox(sInsertStockName,
16, MsgTitle)
78 Sub CellValuetoControl(oSheet, oControl as Object, CellName as String)
81 oCell = GetCellByName(oSheet, CellName)
82 If oControl.PropertySetInfo.HasPropertyByName(
"EffectiveValue
") Then
83 oControl.EffectiveValue = oCell.Value
85 oControl.Value = oCell.Value
87 ' If oCell.FormulaResultType =
1 Then
88 ' StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
89 ' oControl.Text = DeleteStr(StringValue,
"%
")
91 ' oControl.Text = oCell.String
96 Sub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
97 If RowCount
> 0 Then
98 oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
103 Sub AddValueToCellContent(iCellCol, iCellRow as Integer, AddValue)
106 oCell = oMovementSheet.GetCellByPosition(iCellCol, iCellRow)
107 OldValue = oCell.Value
108 oCell.Value = OldValue + AddValue
112 Sub CheckInputDate(aEvent as Object)
113 Dim oRefDialog as Object
114 Dim oRefModel as Object
115 Dim oDateModel as Object
116 oDateModel = aEvent.Source.Model
117 oRefModel = DlgReference.GetControl(
"cmdGoOn
").Model
118 oRefModel.Enabled = oDateModel.Date
<> 0
123 ' Updates the cell with the CurrentValue after checking if the
124 ' Newdate is later than the one that is refered to in the annotation
126 Sub InsertCurrentValue(CurValue as Double, iRow as Integer, Newdate as Date)
129 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1, iRow)
130 OldDate = CDate(oCell.Annotation.Text.String)
131 If NewDate
>= OldDate Then
132 oCell.SetValue(CurValue)
133 oCell.Annotation.Text.SetString(CStr(NewDate))
138 Sub SplitCellValue(oSheet, FirstNumber, SecondNumber, iCol, iRow, NoteText)
141 oCell = oSheet.GetCellByPosition(iCol, iRow)
142 OldValue = oCell.Value
143 oCell.Value = OldValue * FirstNumber / SecondNumber
144 If NoteText
<> "" Then
145 oCell.Annotation.SetString(NoteText)
150 Function GetStockRowIndex(ByVal Stockname) as Integer
151 Dim i, StocksCount as Integer
152 Dim iStartRow as Integer
154 StocksCount = GetStocksCount(iStartRow)
155 For i =
1 To StocksCount
156 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
157 If oCell.String = Stockname Then
158 GetStockRowIndex = iStartRow + i
162 GetStockRowIndex = -
1
166 Function GetStockID(StockName as String, Optional iFirstRow as Integer) as String
167 Dim CellStockName as String
169 Dim iCount as Integer
170 Dim iLastRow as Integer
171 If IsMissing(iFirstRow) Then
172 iFirstRow = GetRowIndex(oFirstSheet,
"HiddenRow1
")
174 iCount = GetStocksCount(iFirstRow)
175 iLastRow = iFirstRow + iCount
176 For i = iFirstRow To iLastRow
177 CellStockName = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1, i).String
178 If CellStockname = StockName Then
182 If i
> iLastRow Then
183 GetStockID() =
""
185 If Not IsMissing(iFirstRow) Then
188 GetStockID() = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
193 Function CheckDocLocale(LocLanguage as String, LocCountry as String)
194 Dim bIsDocLanguage as Boolean
195 Dim bIsDocCountry as Boolean
196 bIsDocLanguage = Instr(
1, LocLanguage, sDocLanguage, SBBINARY)
<> 0
197 bIsDocCountry = Instr(
1, LocCountry, sDocCountry, SBBINARY)
<> 0 OR SDocCountry =
""
198 CheckDocLocale = (bIsDocLanguage And bIsDocCountry)