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