von bst » Mi, 18.08.2010 09:43
Morgen,
mal ein Versuch. Auch wenn die Collections in OOo Basic wohl nicht so schnell sein dürften wie ein Hash (oder auch ein Dictionary-Object in VBScript) sollte das doch deutlich schneller sein,
Zu Collections siehe:
http://www.oooforum.org/forum/viewtopic.phtml?p=387376
Nachtrag: Code um formatiert, d.h. Tabs entfernt ?
cu, Bernd
--
Code: Alles auswählen
REM ***** BasIC *****
Option Explicit
Sub DelDouble
Dim oSheet as Object, oCellCursor as Object, oCellRange as Object
Dim arData as Variant, i as Long, iLastRow as Long
Dim col as New Collection, strKey as String
Dim t as Long
t = Timer
oSheet = ThisComponent.CurrentController.getActiveSheet()
oCellCursor = oSheet.createCursor()
oCellCursor.GotoEndOfUsedArea(True)
iLastRow = oCellCursor.getRangeAddress.EndRow
oCellRange = oSheet.getCellRangeByPosition(0,0,0,iLastRow)
arData = oCellRange.getDataArray
for i = 0 to iLastRow
strKey = Trim(arData(i)(0))
if len(strKey) > 0 Then
if ColItemExists(col, strKey) Then
arData(i)(0) = ""
else
col.Add 0, strKey
endif
endif
next
oCellRange.setDataArray arData
print Timer - t
End Sub
Function ColItemExists(ByVal col as Collection, ByVal strKey as String) as Boolean
On Error Resume Next
ColItemExists = Len(col(strKey)) > 0
End Function
Morgen,
mal ein Versuch. Auch wenn die Collections in OOo Basic wohl nicht so schnell sein dürften wie ein Hash (oder auch ein Dictionary-Object in VBScript) sollte das doch deutlich schneller sein,
Zu Collections siehe: http://www.oooforum.org/forum/viewtopic.phtml?p=387376
Nachtrag: Code um formatiert, d.h. Tabs entfernt ?
cu, Bernd
--
[code]REM ***** BasIC *****
Option Explicit
Sub DelDouble
Dim oSheet as Object, oCellCursor as Object, oCellRange as Object
Dim arData as Variant, i as Long, iLastRow as Long
Dim col as New Collection, strKey as String
Dim t as Long
t = Timer
oSheet = ThisComponent.CurrentController.getActiveSheet()
oCellCursor = oSheet.createCursor()
oCellCursor.GotoEndOfUsedArea(True)
iLastRow = oCellCursor.getRangeAddress.EndRow
oCellRange = oSheet.getCellRangeByPosition(0,0,0,iLastRow)
arData = oCellRange.getDataArray
for i = 0 to iLastRow
strKey = Trim(arData(i)(0))
if len(strKey) > 0 Then
if ColItemExists(col, strKey) Then
arData(i)(0) = ""
else
col.Add 0, strKey
endif
endif
next
oCellRange.setDataArray arData
print Timer - t
End Sub
Function ColItemExists(ByVal col as Collection, ByVal strKey as String) as Boolean
On Error Resume Next
ColItemExists = Len(col(strKey)) > 0
End Function
[/code]