Seite 1 von 1

[Makro] CB-Status/LB-Füllen/Verbesserungsvorschläge?

Verfasst: Mi, 21.12.2011 18:24
von CamuelSpenser
Moin moin ihr Lieben ^^
hab nu mein zweites OOo-Basic Makro geschrieben mit Hilfe dessen was ich in meinem vorherigen Thema vun balu und DPunch gelernt habe, will den beiden hier auch nochmal dafür Danken :)

So bei meinem neuen Makro werden durch anklicken der CheckBox in dem Blatt "Eingabe Kunde" werden mehrere Sachen ausgelöst :

1. Die Oberflächen-ListBox'en im Blatt "Bestellformular" werden gefüllt (resp geleert, wenn unchecked) (LB 50 - 57)
2. In den Blättern "Granit Modul", "Durabo Modul" und "GlassStone Modul" wird Zeile 46 (Index=45) versteckt. bzw angezeigt.

Nun wollt ich euch fragen, ob ihr eventuell Verbesserungsvorschläge habt, wie ich es noch Vereinfacheren könnte?
Oder ob es schon relativ gut ist so?

Code: Alles auswählen

Sub Oberflaechen()
dim I                                      as Integer
dim oDocument, oSheet(5), oDraw(1)         as Object 
dim oForm(1), oControler, oListe, oListBox as Object
dim oCheckBox, oZeile	                   as Object
dim aRangeProperty(0)                      as new com.sun.star.beans.NamedValue
dim oRange, oListSource
	oDocument     = StarDesktop.CurrentComponent
 REM Es folgen die benötigten Sheets
	oSheet(0)     = oDocument.Sheets.GetByName("Eingabe Kunde")
	oSheet(1)     = oDocument.Sheets.GetByName("Bestellformular")
	oSheet(2)     = oDocument.Sheets.GetByName("Granit Modul")		
	oSheet(3)	  = oDocument.Sheets.GetByName("Durabo Modul")
	oSheet(4)	  = oDocument.Sheets.GetByName("GlassStone Modul")
	oDraw(0)      = oSheet(0).DrawPage
	oDraw(1)      = oSheet(1).DrawPage
	oForm(0)      = oDraw(0).Forms.GetByIndex(0)
	oForm(1)      = oDraw(1).Forms.GetByIndex(0)
	oControler    = oDocument.GetCurrentController
 REM Kontrolle über CheckBox erlangen um Status abfragen zu können
	oCheckBox     = oControler.GetControl(oForm(0).GetByName("Check Box 1"))
	if oCheckBox.State(1) then 
 REM When Checked then CellRange = $O$2:$O$7 vom Blatt "HILFSTABELLE"
		oRange  = oDocument.Sheets.GetByName("HILFSTABELLE").GetCellRangeByName("$O$2:$O$7")
 REM Zeile 46 anzeigen auf "Granit Modul, "Durabo Modul", "GlassStone Modul"
		For I = 2 to 4 
			oZeile           = oSheet(I).getrows().GetByIndex(45)
			oZeile.isVisible = True
		Next I	
	else
 REM When Checked then CellRange = $O$2 vom Blatt "HILFSTABELLE"
		oRange  = oDocument.Sheets.GetByName("HILFSTABELLE").GetCellRangeByName("$O$2")
 REM Zeile 46 verstecken auf "Granit Modul, "Durabo Modul", "GlassStone Modul"
		For I = 2 to 4 
			oZeile           = oSheet(I).getrows().GetByIndex(45)
			oZeile.isVisible = False
		Next I
	end if 
	aRangeProperty(0).Name      = "CellRange"
	aRangeProperty(0).Value     = oRange.RangeAddress
	oListSource                 = oDocument.CreateInstanceWithArguments("com.sun.star.table.CellRangeListSource",aRangeProperty)
 REM Listboxen 50-57 befüllen auf Blatt "Bestellformular"
	For I = 50 to 57
		oListe                  = oForm(1).GetByName("List Box " & I)
		oListe.ListSourceType   = com.sun.star.form.ListSourceType.TABLEFIELDS
		oListe.ListEntrySource  = oListSource
	Next I	
end sub	
Im Anhang findet ihr eine Beispiel-Datei :)

Lg aus Luxemburg