xref: /aoo42x/main/wizards/source/depot/tools.xba (revision cdf0e10c)
1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="tools" script:language="StarBasic">REM  *****  BASIC  *****
4*cdf0e10cSrcweirOption Explicit
5*cdf0e10cSrcweir
6*cdf0e10cSrcweirSub RemoveSheet()
7*cdf0e10cSrcweir	If oSheets.HasbyName(&quot;Link&quot;) then
8*cdf0e10cSrcweir		oSheets.RemovebyName(&quot;Link&quot;)
9*cdf0e10cSrcweir	End If
10*cdf0e10cSrcweirEnd Sub
11*cdf0e10cSrcweir
12*cdf0e10cSrcweir
13*cdf0e10cSrcweirSub InitializeStatusLine(StatusText as String, MaxValue as Integer, FirstValue as Integer)
14*cdf0e10cSrcweir	oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
15*cdf0e10cSrcweir	oStatusLine.Start(StatusText, MaxValue)
16*cdf0e10cSrcweir	oStatusline.SetValue(FirstValue)
17*cdf0e10cSrcweirEnd Sub
18*cdf0e10cSrcweir
19*cdf0e10cSrcweir
20*cdf0e10cSrcweirSub MakeRangeVisible(oSheet as Object, RangeName as String, BIsVisible as Boolean)
21*cdf0e10cSrcweirDim oRangeAddress, oColumns as Object
22*cdf0e10cSrcweirDim i, iStartColumn, iEndColumn as Integer
23*cdf0e10cSrcweir	oRangeAddress = oSheet.GetCellRangeByName(RangeName).RangeAddress
24*cdf0e10cSrcweir	iStartColumn = oRangeAddress.StartColumn
25*cdf0e10cSrcweir	iEndColumn = oRangeAddress.EndColumn
26*cdf0e10cSrcweir	oColumns = oSheet.Columns
27*cdf0e10cSrcweir	For i = iStartColumn To iEndColumn
28*cdf0e10cSrcweir		oSheet.Columns(i).IsVisible = bIsVisible
29*cdf0e10cSrcweir	Next i
30*cdf0e10cSrcweirEnd Sub
31*cdf0e10cSrcweir
32*cdf0e10cSrcweir
33*cdf0e10cSrcweirFunction GetRowIndex(oSheet as Object, RowName as String)
34*cdf0e10cSrcweirDim oRange as Object
35*cdf0e10cSrcweir	oRange = oSheet.GetCellRangeByName(RowName)
36*cdf0e10cSrcweir	GetRowIndex = oRange.RangeAddress.StartRow
37*cdf0e10cSrcweirEnd Function
38*cdf0e10cSrcweir
39*cdf0e10cSrcweir
40*cdf0e10cSrcweirFunction GetTransactionCount(iStartRow as Integer)
41*cdf0e10cSrcweirDim iEndRow as Integer
42*cdf0e10cSrcweir	iStartRow = GetRowIndex(oMovementSheet, &quot;ColumnsToHide&quot;)
43*cdf0e10cSrcweir	iEndRow = GetRowIndex(oMovementSheet, &quot;HiddenRow3&quot; )
44*cdf0e10cSrcweir	GetTransactionCount = iEndRow -iStartRow - 2
45*cdf0e10cSrcweirEnd Function
46*cdf0e10cSrcweir
47*cdf0e10cSrcweir
48*cdf0e10cSrcweirFunction GetStocksCount(iStartRow as Integer)
49*cdf0e10cSrcweirDim iEndRow as Integer
50*cdf0e10cSrcweir	iStartRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
51*cdf0e10cSrcweir	iEndRow = GetRowIndex(oFirstSheet, &quot;HiddenRow2&quot;)
52*cdf0e10cSrcweir	GetStocksCount = iEndRow -iStartRow - 1
53*cdf0e10cSrcweirEnd Function
54*cdf0e10cSrcweir
55*cdf0e10cSrcweir
56*cdf0e10cSrcweirFunction FillListbox(ListboxControl as Object, MsgTitle as String, bShowMessage) as Boolean
57*cdf0e10cSrcweirDim i, StocksCount as Integer
58*cdf0e10cSrcweirDim iStartRow as Integer
59*cdf0e10cSrcweirDim oCell as Object
60*cdf0e10cSrcweir	&apos; Add stock names to empty list box
61*cdf0e10cSrcweir	StocksCount = GetStocksCount(iStartRow)
62*cdf0e10cSrcweir	If StocksCount &gt; 0 Then
63*cdf0e10cSrcweir		ListboxControl.Model.StringItemList() = NullList()
64*cdf0e10cSrcweir		For i = 1 To StocksCount
65*cdf0e10cSrcweir			oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
66*cdf0e10cSrcweir			ListboxControl.AddItem(oCell.String, i-1)
67*cdf0e10cSrcweir		Next
68*cdf0e10cSrcweir		FillListbox() = True
69*cdf0e10cSrcweir	Else
70*cdf0e10cSrcweir		If bShowMessage Then
71*cdf0e10cSrcweir			Msgbox(sInsertStockName, 16, MsgTitle)
72*cdf0e10cSrcweir			FillListbox() = False
73*cdf0e10cSrcweir		End If
74*cdf0e10cSrcweir	End If
75*cdf0e10cSrcweirEnd Function
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir
78*cdf0e10cSrcweirSub CellValuetoControl(oSheet, oControl as Object, CellName as String)
79*cdf0e10cSrcweirDim oCell as Object
80*cdf0e10cSrcweirDim StringValue
81*cdf0e10cSrcweir	oCell = GetCellByName(oSheet, CellName)
82*cdf0e10cSrcweir	If oControl.PropertySetInfo.HasPropertyByName(&quot;EffectiveValue&quot;) Then
83*cdf0e10cSrcweir		oControl.EffectiveValue = oCell.Value
84*cdf0e10cSrcweir	Else
85*cdf0e10cSrcweir		oControl.Value = oCell.Value
86*cdf0e10cSrcweir	End If
87*cdf0e10cSrcweir&apos;	If oCell.FormulaResultType = 1 Then
88*cdf0e10cSrcweir&apos;		StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
89*cdf0e10cSrcweir&apos;		oControl.Text = DeleteStr(StringValue, &quot;%&quot;)
90*cdf0e10cSrcweir&apos;	Else
91*cdf0e10cSrcweir&apos;		oControl.Text = oCell.String
92*cdf0e10cSrcweir&apos;	End If
93*cdf0e10cSrcweirEnd Sub
94*cdf0e10cSrcweir
95*cdf0e10cSrcweir
96*cdf0e10cSrcweirSub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
97*cdf0e10cSrcweir	If RowCount &gt; 0 Then
98*cdf0e10cSrcweir		oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
99*cdf0e10cSrcweir	End If
100*cdf0e10cSrcweirEnd Sub
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir
103*cdf0e10cSrcweirSub AddValueToCellContent(iCellCol, iCellRow as Integer, AddValue)
104*cdf0e10cSrcweirDim oCell as Object
105*cdf0e10cSrcweirDim OldValue
106*cdf0e10cSrcweir	oCell = oMovementSheet.GetCellByPosition(iCellCol, iCellRow)
107*cdf0e10cSrcweir	OldValue = oCell.Value
108*cdf0e10cSrcweir	oCell.Value = OldValue + AddValue
109*cdf0e10cSrcweirEnd Sub
110*cdf0e10cSrcweir
111*cdf0e10cSrcweir
112*cdf0e10cSrcweirSub CheckInputDate(aEvent as Object)
113*cdf0e10cSrcweirDim oRefDialog as Object
114*cdf0e10cSrcweirDim oRefModel as Object
115*cdf0e10cSrcweirDim oDateModel as Object
116*cdf0e10cSrcweir	oDateModel = aEvent.Source.Model
117*cdf0e10cSrcweir	oRefModel = DlgReference.GetControl(&quot;cmdGoOn&quot;).Model
118*cdf0e10cSrcweir	oRefModel.Enabled = oDateModel.Date &lt;&gt; 0
119*cdf0e10cSrcweirEnd Sub
120*cdf0e10cSrcweir
121*cdf0e10cSrcweir
122*cdf0e10cSrcweir
123*cdf0e10cSrcweir&apos; Updates the cell with the CurrentValue after checking if the
124*cdf0e10cSrcweir&apos; Newdate is later than the one that is refered to in the annotation
125*cdf0e10cSrcweir&apos; of the cell
126*cdf0e10cSrcweirSub InsertCurrentValue(CurValue as Double, iRow as Integer, Newdate as Date)
127*cdf0e10cSrcweirDim oCell as Object
128*cdf0e10cSrcweirDim OldDate as Date
129*cdf0e10cSrcweir	oCell = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1, iRow)
130*cdf0e10cSrcweir	OldDate = CDate(oCell.Annotation.Text.String)
131*cdf0e10cSrcweir	If NewDate &gt;= OldDate Then
132*cdf0e10cSrcweir		oCell.SetValue(CurValue)
133*cdf0e10cSrcweir		oCell.Annotation.Text.SetString(CStr(NewDate))
134*cdf0e10cSrcweir	End If
135*cdf0e10cSrcweirEnd Sub
136*cdf0e10cSrcweir
137*cdf0e10cSrcweir
138*cdf0e10cSrcweirSub SplitCellValue(oSheet, FirstNumber, SecondNumber, iCol, iRow, NoteText)
139*cdf0e10cSrcweirDim oCell as Object
140*cdf0e10cSrcweirDim OldValue
141*cdf0e10cSrcweir	oCell = oSheet.GetCellByPosition(iCol, iRow)
142*cdf0e10cSrcweir	OldValue = oCell.Value
143*cdf0e10cSrcweir	oCell.Value = OldValue * FirstNumber / SecondNumber
144*cdf0e10cSrcweir	If NoteText &lt;&gt; &quot;&quot; Then
145*cdf0e10cSrcweir		oCell.Annotation.SetString(NoteText)
146*cdf0e10cSrcweir	End If
147*cdf0e10cSrcweirEnd Sub
148*cdf0e10cSrcweir
149*cdf0e10cSrcweir
150*cdf0e10cSrcweirFunction GetStockRowIndex(ByVal Stockname) as Integer
151*cdf0e10cSrcweirDim i, StocksCount as Integer
152*cdf0e10cSrcweirDim iStartRow as Integer
153*cdf0e10cSrcweirDim oCell as Object
154*cdf0e10cSrcweir	StocksCount = GetStocksCount(iStartRow)
155*cdf0e10cSrcweir	For i = 1 To StocksCount
156*cdf0e10cSrcweir		oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
157*cdf0e10cSrcweir		If oCell.String = Stockname Then
158*cdf0e10cSrcweir			GetStockRowIndex = iStartRow + i
159*cdf0e10cSrcweir			Exit Function
160*cdf0e10cSrcweir		End If
161*cdf0e10cSrcweir	Next
162*cdf0e10cSrcweir	GetStockRowIndex = -1
163*cdf0e10cSrcweirEnd Function
164*cdf0e10cSrcweir
165*cdf0e10cSrcweir
166*cdf0e10cSrcweirFunction GetStockID(StockName as String, Optional iFirstRow as Integer) as String
167*cdf0e10cSrcweirDim CellStockName as String
168*cdf0e10cSrcweirDim i as Integer
169*cdf0e10cSrcweirDim iCount as Integer
170*cdf0e10cSrcweirDim iLastRow as Integer
171*cdf0e10cSrcweir	If IsMissing(iFirstRow) Then
172*cdf0e10cSrcweir		iFirstRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
173*cdf0e10cSrcweir	End If
174*cdf0e10cSrcweir	iCount = GetStocksCount(iFirstRow)
175*cdf0e10cSrcweir	iLastRow = iFirstRow + iCount
176*cdf0e10cSrcweir	For i = iFirstRow To iLastRow
177*cdf0e10cSrcweir		CellStockName = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1, i).String
178*cdf0e10cSrcweir		If CellStockname = StockName Then
179*cdf0e10cSrcweir			Exit For
180*cdf0e10cSrcweir		End If
181*cdf0e10cSrcweir	Next i
182*cdf0e10cSrcweir	If i &gt; iLastRow Then
183*cdf0e10cSrcweir		GetStockID() = &quot;&quot;
184*cdf0e10cSrcweir	Else
185*cdf0e10cSrcweir		If Not IsMissing(iFirstRow) Then
186*cdf0e10cSrcweir			iFirstRow = i
187*cdf0e10cSrcweir		End If
188*cdf0e10cSrcweir		GetStockID() = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
189*cdf0e10cSrcweir	End If
190*cdf0e10cSrcweirEnd Function
191*cdf0e10cSrcweir
192*cdf0e10cSrcweir
193*cdf0e10cSrcweirFunction CheckDocLocale(LocLanguage as String, LocCountry as String)
194*cdf0e10cSrcweirDim bIsDocLanguage as Boolean
195*cdf0e10cSrcweirDim bIsDocCountry as Boolean
196*cdf0e10cSrcweir	bIsDocLanguage = Instr(1, LocLanguage, sDocLanguage, SBBINARY) &lt;&gt; 0
197*cdf0e10cSrcweir	bIsDocCountry = Instr(1, LocCountry, sDocCountry, SBBINARY) &lt;&gt; 0 OR SDocCountry = &quot;&quot;
198*cdf0e10cSrcweir	CheckDocLocale = (bIsDocLanguage And bIsDocCountry)
199*cdf0e10cSrcweirEnd Function
200*cdf0e10cSrcweir</script:module>