home *** CD-ROM | disk | FTP | other *** search
/ Freelog 52 / Freelog052.iso / Dossier / OpenOffice / f_0214 / tools.xba < prev   
Extensible Markup Language  |  2002-09-17  |  6KB  |  200 lines

  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
  5.  
  6. Sub RemoveSheet()
  7.     If oSheets.HasbyName("Link") then
  8.         oSheets.RemovebyName("Link")
  9.     End If
  10. End Sub
  11.  
  12.  
  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
  18.  
  19.  
  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
  31.  
  32.  
  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    
  38.  
  39.  
  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
  45. End Function    
  46.  
  47.  
  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
  53. End Function
  54.  
  55.  
  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.     ' 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)
  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
  76.  
  77.  
  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("EffectiveValue") Then
  83.         oControl.EffectiveValue = oCell.Value
  84.     Else    
  85.         oControl.Value = oCell.Value
  86.     End If
  87. '    If oCell.FormulaResultType = 1 Then
  88. '        StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
  89. '        oControl.Text = DeleteStr(StringValue, "%")
  90. '    Else
  91. '        oControl.Text = oCell.String
  92. '    End If
  93. End Sub
  94.  
  95.  
  96. Sub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
  97.     If RowCount > 0 Then
  98.         oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
  99.     End If
  100. End Sub
  101.  
  102.  
  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                    
  110.  
  111.  
  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
  119. End Sub
  120.  
  121.  
  122.  
  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
  125. ' of the cell
  126. Sub InsertCurrentValue(CurValue, 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 >= OldDate Then
  132.         oCell.SetValue(CurValue)
  133.         oCell.Annotation.Text.SetString(CStr(NewDate))
  134.     End If
  135. End Sub
  136.  
  137.  
  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 <> "" Then
  145.         oCell.Annotation.SetString(NoteText)
  146.     End If
  147. End Sub            
  148.  
  149.  
  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
  164.  
  165.  
  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, "HiddenRow1")
  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 > iLastRow Then
  183.         GetStockID() = ""
  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
  191.  
  192.  
  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)
  199. End Function
  200. </script:module>