進捗状況を示すステータスバー(プログレスバー)を表示するには以下の方法があります。
1) 画面のステータスバーに表示
1-1) StatusIndicator
1-2) ScriptForge を利用( CreateScriptService("UI") / SetStatusbar )
2) Formに表示
2-1) ScriptForge を利用( ShowProgressBar )
2-2) Dialog Formを作成
Sample Codeは以下
Sub StatusIndicator()
Dim oDoc as Object
Dim oSI as Object
oDoc = ThisComponent
oSI = oDoc.CurrentController.StatusIndicator
oEnd = 100
'Indicator bar Reset
oSI.Reset
oSI.Start("Excuting",oEnd)
For i = 0 to 10
oSI.setText("Excuting " & 10*i & " / " & oEnd)
oSI.setValue(i * 10 + 10)
wait(300) ' 1 sec
next i
Msgbox("StatusBarのテキストをリセット。",0,"StatusBar")
oSI.Reset
Msgbox("StatusBarを終了。",0,"StatusBar")
oSI.end()
End Sub
【 解説 】
ScriptForge を利用を利用する方法です。
※ メソッドを利用する場合は
.StatusIndicator ⇒ .getStatusIndicator()
を使います。
Sub StatusIndicator()
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Dim ui as Object
Dim i As Integer
Set ui = CreateScriptService("UI")
For i = 0 to 10
ui.SetStatusbar("Progress ...", i * 10 + 10)
wait 300
next i
Msgbox("StatusBarを終了。",0,"StatusBar")
ui.SetStatusbar
End Sub
【 解説 】
ScriptForgeを利用する方法です。
StatusIndicatorプロパティとの違いは、IDEでマクロを実行した時に
・StatusIndicatorプロパティ : ステータスバーは表示されない
・ScriptForge : IDEでもステータスバーが表示される
ことです。
Sub StatusIndicator()
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Dim ui as Object
Dim i As Integer
Set ui = CreateScriptService("UI")
For i = 0 to 100
ui.ShowProgressBar("Window Title", "Progress ..." & i & "/100", i)
wait 50
next i
Msgbox("Formを閉じる。",0,"StatusBar")
ui.ShowProgressBar
End Sub
【 解説 】
ScriptForgeで StatusDialogを表示する方法です。
Dialogの細かい設定はできませんが、容易に表示できるので有用性が高いです。
ui.ShowProgressBar(第1引数, 第2引数, 第3引数)
第1引数: Dialog Fom(Window)のタイトル
第2引数: テキスト表示
第3引数: ステータスバーの値
Sub DialogMacro()
Dim oDlg as Object 'The created dialog.
Dim oDlgModel as Object 'The created dialog's model.
Dim oTabIndex% 'The current tab index while creating controls.
Dim oModel as Object 'Model for a control.
Dim oDlgWth as Long
Dim oDlgHgt as Long
'
' Create the dialog's model
oDlgModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
'
' Size of Dialog
oDlgWth = 120
oDlgHgt = 80
'
oDlgModel.Width = oDlgWth
oDlgModel.Height = oDlgHgt
' Title of Dialog
oDlgModel.Title = "Dialog Title"
'
' ***** [ Close Button 設定 ] *****
' OK Button 仕様
oModel = oDlgModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
oTabIndex = 0 ' Tab番号
'
oModel.Name = "StepButton"
oModel.TabIndex = oTabIndex
oModel.PositionX = CLng(oDlgWth/2 - 20)
oModel.PositionY = oDlgHgt - 20
oModel.Width = 40
oModel.Height = 15
oModel.Label = "Close"
oModel.PushButtonType = com.sun.star.awt.PushButtonType.OK
'
' Dialog Modelの仕様に OK Button の仕様を設定
oDlgModel.insertByName("StepButton", oModel)
'
' ***** [ Close Button 設定 ] *****
'
'
' ***** [ ProgressBar 設定 ] *****
' ProgressBar 仕様
oModel = oDlgModel.createInstance("com.sun.star.awt.UnoControlProgressBarModel")
oTabIndex = oTabIndex + 1
'
oModel.Name = "Progress"
oModel.TabIndex = oTabIndex
oModel.PositionX = 10
oModel.PositionY = oDlgHgt - 45
oModel.Width = oDlgWth - 20
oModel.Height = 15
oModel.ProgressValueMin = 0
oModel.ProgressValueMax = 100
'
' Dialog Modelの仕様に OK Button の仕様を設定
oDlgModel.insertByName("Progress", oModel)
' ***** [ ProgressBar 設定 ] *****
'
'
' Create the dialog and set the model
oDlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oDlg.setModel(oDlgModel)
'
'
' Create a window and then tell the dialog to use the created window.
Dim oWindow as Object
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
' Dialogを作成表示
oDlg.createPeer(oWindow, null)
'
oProgressBar = oDlgModel.getByName("Progress")
oProgressBar.ProgressValue = 0
for i = 0 to 100 step 5
oProgressBar.ProgressValue = i * 1
If oProgressBar.ProgressValue >100 then
Exit For
End If
wait 300
next i
'Close Btn処置
oDlg.execute()
oDlg.endExecute()
'
oDisp = "Success"
msgbox(oDisp,0,"Click Button")
End Sub