update dev300-m58
[ooovba.git] / wizards / source / depot / tools.xba
blob6399805419ee545e038f7b7e70d086d9874840c0
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 *****
4 Option Explicit
6 Sub RemoveSheet()
7 If oSheets.HasbyName(&quot;Link&quot;) then
8 oSheets.RemovebyName(&quot;Link&quot;)
9 End If
10 End Sub
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)
17 End Sub
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
29 Next i
30 End Sub
33 Function GetRowIndex(oSheet as Object, RowName as String)
34 Dim oRange as Object
35 oRange = oSheet.GetCellRangeByName(RowName)
36 GetRowIndex = oRange.RangeAddress.StartRow
37 End Function
40 Function GetTransactionCount(iStartRow as Integer)
41 Dim iEndRow as Integer
42 iStartRow = GetRowIndex(oMovementSheet, &quot;ColumnsToHide&quot;)
43 iEndRow = GetRowIndex(oMovementSheet, &quot;HiddenRow3&quot; )
44 GetTransactionCount = iEndRow -iStartRow - 2
45 End Function
48 Function GetStocksCount(iStartRow as Integer)
49 Dim iEndRow as Integer
50 iStartRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
51 iEndRow = GetRowIndex(oFirstSheet, &quot;HiddenRow2&quot;)
52 GetStocksCount = iEndRow -iStartRow - 1
53 End Function
56 Function FillListbox(ListboxControl as Object, MsgTitle as String, bShowMessage) as Boolean
57 Dim i, StocksCount as Integer
58 Dim iStartRow as Integer
59 Dim oCell as Object
60 &apos; Add stock names to empty list box
61 StocksCount = GetStocksCount(iStartRow)
62 If StocksCount &gt; 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)
67 Next
68 FillListbox() = True
69 Else
70 If bShowMessage Then
71 Msgbox(sInsertStockName, 16, MsgTitle)
72 FillListbox() = False
73 End If
74 End If
75 End Function
78 Sub CellValuetoControl(oSheet, oControl as Object, CellName as String)
79 Dim oCell as Object
80 Dim StringValue
81 oCell = GetCellByName(oSheet, CellName)
82 If oControl.PropertySetInfo.HasPropertyByName(&quot;EffectiveValue&quot;) Then
83 oControl.EffectiveValue = oCell.Value
84 Else
85 oControl.Value = oCell.Value
86 End If
87 &apos; If oCell.FormulaResultType = 1 Then
88 &apos; StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
89 &apos; oControl.Text = DeleteStr(StringValue, &quot;%&quot;)
90 &apos; Else
91 &apos; oControl.Text = oCell.String
92 &apos; End If
93 End Sub
96 Sub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
97 If RowCount &gt; 0 Then
98 oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
99 End If
100 End Sub
103 Sub AddValueToCellContent(iCellCol, iCellRow as Integer, AddValue)
104 Dim oCell as Object
105 Dim OldValue
106 oCell = oMovementSheet.GetCellByPosition(iCellCol, iCellRow)
107 OldValue = oCell.Value
108 oCell.Value = OldValue + AddValue
109 End Sub
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(&quot;cmdGoOn&quot;).Model
118 oRefModel.Enabled = oDateModel.Date &lt;&gt; 0
119 End Sub
123 &apos; Updates the cell with the CurrentValue after checking if the
124 &apos; Newdate is later than the one that is refered to in the annotation
125 &apos; of the cell
126 Sub InsertCurrentValue(CurValue as Double, iRow as Integer, Newdate as Date)
127 Dim oCell as Object
128 Dim OldDate as Date
129 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1, iRow)
130 OldDate = CDate(oCell.Annotation.Text.String)
131 If NewDate &gt;= OldDate Then
132 oCell.SetValue(CurValue)
133 oCell.Annotation.Text.SetString(CStr(NewDate))
134 End If
135 End Sub
138 Sub SplitCellValue(oSheet, FirstNumber, SecondNumber, iCol, iRow, NoteText)
139 Dim oCell as Object
140 Dim OldValue
141 oCell = oSheet.GetCellByPosition(iCol, iRow)
142 OldValue = oCell.Value
143 oCell.Value = OldValue * FirstNumber / SecondNumber
144 If NoteText &lt;&gt; &quot;&quot; Then
145 oCell.Annotation.SetString(NoteText)
146 End If
147 End Sub
150 Function GetStockRowIndex(ByVal Stockname) as Integer
151 Dim i, StocksCount as Integer
152 Dim iStartRow as Integer
153 Dim oCell as Object
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
159 Exit Function
160 End If
161 Next
162 GetStockRowIndex = -1
163 End Function
166 Function GetStockID(StockName as String, Optional iFirstRow as Integer) as String
167 Dim CellStockName as String
168 Dim i as Integer
169 Dim iCount as Integer
170 Dim iLastRow as Integer
171 If IsMissing(iFirstRow) Then
172 iFirstRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
173 End If
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
179 Exit For
180 End If
181 Next i
182 If i &gt; iLastRow Then
183 GetStockID() = &quot;&quot;
184 Else
185 If Not IsMissing(iFirstRow) Then
186 iFirstRow = i
187 End If
188 GetStockID() = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
189 End If
190 End Function
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) &lt;&gt; 0
197 bIsDocCountry = Instr(1, LocCountry, sDocCountry, SBBINARY) &lt;&gt; 0 OR SDocCountry = &quot;&quot;
198 CheckDocLocale = (bIsDocLanguage And bIsDocCountry)
199 End Function
200 </script:module>