' Example.vbs Option Explicit MsgBox "選択画面を表示", vbInformation Or vbSystemModal Dim indexArray indexArray = CreateObject("ExampleProject.clsHist").ShowDialog Dim cnt, idx, s cnt = UBound(indexArray) - LBound(indexArray) + 1 s = "選択されたアイテムの総数:" & CStr(cnt) For Each idx In indexArray s = s & vbCrLf & "Index=" & CStr(idx) Next MsgBox s, vbInformation Or vbSystemModal, "列挙終了"
' clsHist.cls Option Explicit Public Function ShowDialog() As Variant Dim dlg As frmHist Set dlg = New frmHist Load dlg dlg.Show vbModal ShowDialog = dlg.SelectedIndices Set dlg = Nothing End Function
'frmHist.frm Option Explicit Option Base 0 Private m_selectedIndices() As Variant Friend Property Get SelectedIndices() As Variant() SelectedIndices = m_selectedIndices End Property Private Sub Form_Initialize() Set frmHist = Nothing End Sub Private Sub Form_Load() m_selectedIndices = Array() cmdOK.Default = True End Sub Private Sub cmdOK_Click() Dim indexArray() As Variant If List1.ListIndex = -1 Then indexArray = Array() Else ReDim indexArray(List1.SelCount - 1) Dim idx As Integer, n As Integer n = -1 For idx = 0 To List1.ListCount - 1 If List1.Selected(idx) Then n = n + 1 indexArray(n) = idx End If Next End If Unload Me m_selectedIndices = indexArray End Sub