von Karbrüggen » Di, 26.09.2006 16:09
Sorry, unformatierter Code mach komische Dinge mit mir
Code: Alles auswählen
Sub GroKlei
Dim sText As String
sText=""
'aktuelles Dokument
xDoc=ThisComponent
xController=xDoc.CurrentController
'Cursor im Doc
xVCrsr=xController.getViewCursor
CurPos=xVCrsr.getPosition()
'gesamtes Dokument
oText=xDoc.Text
xSelection = xDoc.CurrentController.getSelection
'Range des aktuellen Selection
xRange=xSelection(0)
xCursor=xRange.getText.createTExtCursorByRange(xRange)
'Wort markieren
sText=xCursor.GetString()
If Len(sText) <= 0 Then
xCursor.gotoStartOfWord(False)
xCursor.GotoEndOfWord(True)
'String aus Wort ermitteln
sText=xCursor.GetString()
End If
'klein > groß
If sText=LCase(sText) Then
sText=UCase(Left$(sText,1)) + Right$(sText, Len(sText)-1)
'Einfügen
oText.InsertString(xCursor,sText,True)
Exit Sub
End If
'groß > klein
If sText=UCase(sText) Then
oText.InsertString(xCursor,strConvert(stext,0),True)
Exit Sub
End If
'gemischt
If Left$(sText,1) = UCase(Left$(sText,1)) Then
oText.InsertString(xCursor,strConvert(stext,1),True)
Exit Sub
End If
oText.InsertString(xCursor,strConvert(stext,1),True)
End Sub
Function strConvert (cText As String, Flag As Integer) As String
iRun = 1
while iRun < Len(cText)+1
If Flag=1 Then
Mid( cText ,iRun, 1, UCase(Mid(cText,iRun,1))
Else
Mid( cText ,iRun, 1, LCase(Mid(cText,iRun,1))
End If
iRun = iRun + 1
Wend
strConvert=cText
End Function
sub halbesLeer
'define variables
dim document as object
dim dispatcher as object
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:InsertNonBreakingSpace", "", 0, Array())
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args2())
dim args3(2) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Escapement.Escapement"
args3(0).Value = -101
args3(1).Name = "Escapement.Height"
args3(1).Value = 45
args3(2).Name = "Escapement.Auto"
args3(2).Value = true
dispatcher.executeDispatch(document, ".uno:Escapement", "", 0, args3())
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Count"
args4(0).Value = 1
args4(1).Name = "Select"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args4())
end sub
sub halbgeviertstrich
'define variables
dim document as object
dim dispatcher as object
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "–"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub
Sub Typo_Zeichen
oDoc = thisComponent
oViewC = oDoc.getCurrentController().getViewCursor()
oDoc.text.insertString(oViewC.start, chr(8222), false)
oDoc.text.insertString(oViewC.end, chr(8220), false)
End Sub
sub zumBeispiel
'define variables
dim document as object
dim dispatcher as object
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "z."
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:InsertNonBreakingSpace", "", 0, Array())
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Text"
args3(0).Value = "B."
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args3())
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Count"
args4(0).Value = 1
args4(1).Name = "Select"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args4())
dim args5(1) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Count"
args5(0).Value = 1
args5(1).Name = "Select"
args5(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args5())
dim args6(1) as new com.sun.star.beans.PropertyValue
args6(0).Name = "Count"
args6(0).Value = 1
args6(1).Name = "Select"
args6(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args6())
dim args7(2) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Escapement.Escapement"
args7(0).Value = 101
args7(1).Name = "Escapement.Height"
args7(1).Value = 40
args7(2).Name = "Escapement.Auto"
args7(2).Value = true
dispatcher.executeDispatch(document, ".uno:Escapement", "", 0, args7())
dim args8(1) as new com.sun.star.beans.PropertyValue
args8(0).Name = "Count"
args8(0).Value = 1
args8(1).Name = "Select"
args8(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args8())
dim args9(1) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Count"
args9(0).Value = 1
args9(1).Name = "Select"
args9(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args9())
dim args10(1) as new com.sun.star.beans.PropertyValue
args10(0).Name = "Count"
args10(0).Value = 1
args10(1).Name = "Select"
args10(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args10())
end sub
Ich hab lang genug Python geschrieben um zu wissen, wie nützlich Einrückungen und Abstände im Quellcode sind

(Dies führt michzurück zu (La)TeX: der Erfinder (Donald Knuth) ist Autor der Bücherserie "
The Art of Computer Programming" - darin beschreibt er u.a. wie wichtig es ist, Code ordentlich zu schreiben

)
Sorry, unformatierter Code mach komische Dinge mit mir ;-)
[code]Sub GroKlei
Dim sText As String
sText=""
'aktuelles Dokument
xDoc=ThisComponent
xController=xDoc.CurrentController
'Cursor im Doc
xVCrsr=xController.getViewCursor
CurPos=xVCrsr.getPosition()
'gesamtes Dokument
oText=xDoc.Text
xSelection = xDoc.CurrentController.getSelection
'Range des aktuellen Selection
xRange=xSelection(0)
xCursor=xRange.getText.createTExtCursorByRange(xRange)
'Wort markieren
sText=xCursor.GetString()
If Len(sText) <= 0 Then
xCursor.gotoStartOfWord(False)
xCursor.GotoEndOfWord(True)
'String aus Wort ermitteln
sText=xCursor.GetString()
End If
'klein > groß
If sText=LCase(sText) Then
sText=UCase(Left$(sText,1)) + Right$(sText, Len(sText)-1)
'Einfügen
oText.InsertString(xCursor,sText,True)
Exit Sub
End If
'groß > klein
If sText=UCase(sText) Then
oText.InsertString(xCursor,strConvert(stext,0),True)
Exit Sub
End If
'gemischt
If Left$(sText,1) = UCase(Left$(sText,1)) Then
oText.InsertString(xCursor,strConvert(stext,1),True)
Exit Sub
End If
oText.InsertString(xCursor,strConvert(stext,1),True)
End Sub
Function strConvert (cText As String, Flag As Integer) As String
iRun = 1
while iRun < Len(cText)+1
If Flag=1 Then
Mid( cText ,iRun, 1, UCase(Mid(cText,iRun,1))
Else
Mid( cText ,iRun, 1, LCase(Mid(cText,iRun,1))
End If
iRun = iRun + 1
Wend
strConvert=cText
End Function
sub halbesLeer
'define variables
dim document as object
dim dispatcher as object
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:InsertNonBreakingSpace", "", 0, Array())
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args2())
dim args3(2) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Escapement.Escapement"
args3(0).Value = -101
args3(1).Name = "Escapement.Height"
args3(1).Value = 45
args3(2).Name = "Escapement.Auto"
args3(2).Value = true
dispatcher.executeDispatch(document, ".uno:Escapement", "", 0, args3())
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Count"
args4(0).Value = 1
args4(1).Name = "Select"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args4())
end sub
sub halbgeviertstrich
'define variables
dim document as object
dim dispatcher as object
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "–"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub
Sub Typo_Zeichen
oDoc = thisComponent
oViewC = oDoc.getCurrentController().getViewCursor()
oDoc.text.insertString(oViewC.start, chr(8222), false)
oDoc.text.insertString(oViewC.end, chr(8220), false)
End Sub
sub zumBeispiel
'define variables
dim document as object
dim dispatcher as object
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "z."
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:InsertNonBreakingSpace", "", 0, Array())
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Text"
args3(0).Value = "B."
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args3())
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Count"
args4(0).Value = 1
args4(1).Name = "Select"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args4())
dim args5(1) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Count"
args5(0).Value = 1
args5(1).Name = "Select"
args5(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args5())
dim args6(1) as new com.sun.star.beans.PropertyValue
args6(0).Name = "Count"
args6(0).Value = 1
args6(1).Name = "Select"
args6(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args6())
dim args7(2) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Escapement.Escapement"
args7(0).Value = 101
args7(1).Name = "Escapement.Height"
args7(1).Value = 40
args7(2).Name = "Escapement.Auto"
args7(2).Value = true
dispatcher.executeDispatch(document, ".uno:Escapement", "", 0, args7())
dim args8(1) as new com.sun.star.beans.PropertyValue
args8(0).Name = "Count"
args8(0).Value = 1
args8(1).Name = "Select"
args8(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args8())
dim args9(1) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Count"
args9(0).Value = 1
args9(1).Name = "Select"
args9(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args9())
dim args10(1) as new com.sun.star.beans.PropertyValue
args10(0).Name = "Count"
args10(0).Value = 1
args10(1).Name = "Select"
args10(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args10())
end sub[/code]
Ich hab lang genug Python geschrieben um zu wissen, wie nützlich Einrückungen und Abstände im Quellcode sind ;-)
(Dies führt michzurück zu (La)TeX: der Erfinder (Donald Knuth) ist Autor der Bücherserie "[i]The Art of Computer Programming[/i]" - darin beschreibt er u.a. wie wichtig es ist, Code ordentlich zu schreiben ;-))