<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ListBox - MultiSelect in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687911#M33282</link>
    <description>MultiListBox.Selected(cnt)&lt;BR /&gt;
This just returns a Boolean value of whether the ListBox Item at the cnt &lt;BR /&gt;
index is selected.&lt;BR /&gt;
&lt;BR /&gt;
You use this to iterate the ListBox items and determine if an item has been &lt;BR /&gt;
selected.&lt;BR /&gt;
&lt;BR /&gt;
This does what you were expecting:&lt;BR /&gt;
Private Sub OkButton_Click()&lt;BR /&gt;
Dim cnt As Integer&lt;BR /&gt;
Dim aSelctd() As String&lt;BR /&gt;
Dim I As Integer&lt;BR /&gt;
&lt;BR /&gt;
ReDim aSelctd(0 To MultiListBox.ListCount - 1)&lt;BR /&gt;
For cnt = 0 To MultiListBox.ListCount - 1&lt;BR /&gt;
    If MultiListBox.Selected(cnt) = True Then&lt;BR /&gt;
        aSelctd(I) = MultiListBox.List(cnt)&lt;BR /&gt;
        I = I + 1&lt;BR /&gt;
    End If&lt;BR /&gt;
Next&lt;BR /&gt;
ReDim Preserve aSelctd(0 To I - 1)&lt;BR /&gt;
SetLispVar "jb%MultiSelect", aSelctd&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
"James Buzbee" &lt;JDB&gt; wrote in message &lt;BR /&gt;
news:5219172@discussion.autodesk.com...&lt;BR /&gt;
This should work, right?&lt;BR /&gt;
&lt;BR /&gt;
'SetLispVar provided by Tony Tanzillo&lt;BR /&gt;
Public Sub SetLispVar(Symbol As String, Value)&lt;BR /&gt;
Dim vlapp As Object&lt;BR /&gt;
Dim vlFuncs As Object&lt;BR /&gt;
Dim vlSet As Object&lt;BR /&gt;
Dim vSym&lt;BR /&gt;
Set vlapp = CreateObject("Vl.Application.16")&lt;BR /&gt;
Set vlFuncs = vlapp.ActiveDocument.Functions&lt;BR /&gt;
Set vSym = vlFuncs.Item("read").funcall(Symbol)&lt;BR /&gt;
Set vlSet = vlFuncs.Item("set")&lt;BR /&gt;
Select Case VarType(Value)&lt;BR /&gt;
Case vbByte, vbInteger, vbLong&lt;BR /&gt;
Dim lVal As Long&lt;BR /&gt;
lVal = Value&lt;BR /&gt;
vlSet.funcall vSym, lVal&lt;BR /&gt;
Case vbString&lt;BR /&gt;
Dim strVal As String&lt;BR /&gt;
strVal = Value&lt;BR /&gt;
vlSet.funcall vSym, strVal&lt;BR /&gt;
Case vbDouble&lt;BR /&gt;
Dim dblVal As String&lt;BR /&gt;
dblVal = Value&lt;BR /&gt;
vlSet.funcall vSym, dblVal&lt;BR /&gt;
Case vbEmpty&lt;BR /&gt;
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")&lt;BR /&gt;
Case Else&lt;BR /&gt;
If IsArray(Value) Then&lt;BR /&gt;
Dim List As Variant&lt;BR /&gt;
List = Value&lt;BR /&gt;
vlSet.funcall vSym, List&lt;BR /&gt;
Else&lt;BR /&gt;
vlSet.funcall vSym, Value&lt;BR /&gt;
End If&lt;BR /&gt;
End Select&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'populate a multiselect ListBox with Layer names&lt;BR /&gt;
Private Sub UserForm_Initialize()&lt;BR /&gt;
For Each Entry In ThisDrawing.Layers&lt;BR /&gt;
MultiListBox.AddItem Entry.Name&lt;BR /&gt;
Next&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'pass the selected layer names to the Lisp Variable "jb%MultiSelect"&lt;BR /&gt;
Private Sub OkButton_Click()&lt;BR /&gt;
Dim cnt As Integer&lt;BR /&gt;
cnt = MultiListBox.ListCount - 1&lt;BR /&gt;
SetLispVar "jb%MultiSelect", MultiListBox.Selected(cnt)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
(vlax-safearray-&amp;gt;list(vlax-variant-value jb%MultiSelect)) should return a&lt;BR /&gt;
list of the selected layer names.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts???&lt;BR /&gt;
&lt;BR /&gt;
thanks,&lt;BR /&gt;
&lt;BR /&gt;
jb&lt;/JDB&gt;</description>
    <pubDate>Mon, 26 Jun 2006 21:36:03 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-06-26T21:36:03Z</dc:date>
    <item>
      <title>ListBox - MultiSelect</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687910#M33281</link>
      <description>This should work, right?&lt;BR /&gt;
&lt;BR /&gt;
'SetLispVar provided by Tony Tanzillo&lt;BR /&gt;
Public Sub SetLispVar(Symbol As String, Value)&lt;BR /&gt;
Dim vlapp As Object&lt;BR /&gt;
Dim vlFuncs As Object&lt;BR /&gt;
Dim vlSet As Object&lt;BR /&gt;
Dim vSym&lt;BR /&gt;
Set vlapp = CreateObject("Vl.Application.16")&lt;BR /&gt;
Set vlFuncs = vlapp.ActiveDocument.Functions&lt;BR /&gt;
Set vSym = vlFuncs.Item("read").funcall(Symbol)&lt;BR /&gt;
Set vlSet = vlFuncs.Item("set")&lt;BR /&gt;
Select Case VarType(Value)&lt;BR /&gt;
Case vbByte, vbInteger, vbLong&lt;BR /&gt;
Dim lVal As Long&lt;BR /&gt;
lVal = Value&lt;BR /&gt;
vlSet.funcall vSym, lVal&lt;BR /&gt;
Case vbString&lt;BR /&gt;
Dim strVal As String&lt;BR /&gt;
strVal = Value&lt;BR /&gt;
vlSet.funcall vSym, strVal&lt;BR /&gt;
Case vbDouble&lt;BR /&gt;
Dim dblVal As String&lt;BR /&gt;
dblVal = Value&lt;BR /&gt;
vlSet.funcall vSym, dblVal&lt;BR /&gt;
Case vbEmpty&lt;BR /&gt;
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")&lt;BR /&gt;
Case Else&lt;BR /&gt;
If IsArray(Value) Then&lt;BR /&gt;
Dim List As Variant&lt;BR /&gt;
List = Value&lt;BR /&gt;
vlSet.funcall vSym, List&lt;BR /&gt;
Else&lt;BR /&gt;
vlSet.funcall vSym, Value&lt;BR /&gt;
End If&lt;BR /&gt;
End Select&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'populate a multiselect ListBox with Layer names&lt;BR /&gt;
Private Sub UserForm_Initialize()&lt;BR /&gt;
For Each Entry In ThisDrawing.Layers&lt;BR /&gt;
MultiListBox.AddItem Entry.Name&lt;BR /&gt;
Next&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'pass the selected layer names to the Lisp Variable "jb%MultiSelect"&lt;BR /&gt;
Private Sub OkButton_Click()&lt;BR /&gt;
Dim cnt As Integer&lt;BR /&gt;
cnt = MultiListBox.ListCount - 1&lt;BR /&gt;
SetLispVar "jb%MultiSelect", MultiListBox.Selected(cnt)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
(vlax-safearray-&amp;gt;list(vlax-variant-value jb%MultiSelect)) should return a &lt;BR /&gt;
list of the selected layer names.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts???&lt;BR /&gt;
&lt;BR /&gt;
thanks,&lt;BR /&gt;
&lt;BR /&gt;
jb</description>
      <pubDate>Mon, 26 Jun 2006 20:59:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687910#M33281</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-26T20:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: ListBox - MultiSelect</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687911#M33282</link>
      <description>MultiListBox.Selected(cnt)&lt;BR /&gt;
This just returns a Boolean value of whether the ListBox Item at the cnt &lt;BR /&gt;
index is selected.&lt;BR /&gt;
&lt;BR /&gt;
You use this to iterate the ListBox items and determine if an item has been &lt;BR /&gt;
selected.&lt;BR /&gt;
&lt;BR /&gt;
This does what you were expecting:&lt;BR /&gt;
Private Sub OkButton_Click()&lt;BR /&gt;
Dim cnt As Integer&lt;BR /&gt;
Dim aSelctd() As String&lt;BR /&gt;
Dim I As Integer&lt;BR /&gt;
&lt;BR /&gt;
ReDim aSelctd(0 To MultiListBox.ListCount - 1)&lt;BR /&gt;
For cnt = 0 To MultiListBox.ListCount - 1&lt;BR /&gt;
    If MultiListBox.Selected(cnt) = True Then&lt;BR /&gt;
        aSelctd(I) = MultiListBox.List(cnt)&lt;BR /&gt;
        I = I + 1&lt;BR /&gt;
    End If&lt;BR /&gt;
Next&lt;BR /&gt;
ReDim Preserve aSelctd(0 To I - 1)&lt;BR /&gt;
SetLispVar "jb%MultiSelect", aSelctd&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
"James Buzbee" &lt;JDB&gt; wrote in message &lt;BR /&gt;
news:5219172@discussion.autodesk.com...&lt;BR /&gt;
This should work, right?&lt;BR /&gt;
&lt;BR /&gt;
'SetLispVar provided by Tony Tanzillo&lt;BR /&gt;
Public Sub SetLispVar(Symbol As String, Value)&lt;BR /&gt;
Dim vlapp As Object&lt;BR /&gt;
Dim vlFuncs As Object&lt;BR /&gt;
Dim vlSet As Object&lt;BR /&gt;
Dim vSym&lt;BR /&gt;
Set vlapp = CreateObject("Vl.Application.16")&lt;BR /&gt;
Set vlFuncs = vlapp.ActiveDocument.Functions&lt;BR /&gt;
Set vSym = vlFuncs.Item("read").funcall(Symbol)&lt;BR /&gt;
Set vlSet = vlFuncs.Item("set")&lt;BR /&gt;
Select Case VarType(Value)&lt;BR /&gt;
Case vbByte, vbInteger, vbLong&lt;BR /&gt;
Dim lVal As Long&lt;BR /&gt;
lVal = Value&lt;BR /&gt;
vlSet.funcall vSym, lVal&lt;BR /&gt;
Case vbString&lt;BR /&gt;
Dim strVal As String&lt;BR /&gt;
strVal = Value&lt;BR /&gt;
vlSet.funcall vSym, strVal&lt;BR /&gt;
Case vbDouble&lt;BR /&gt;
Dim dblVal As String&lt;BR /&gt;
dblVal = Value&lt;BR /&gt;
vlSet.funcall vSym, dblVal&lt;BR /&gt;
Case vbEmpty&lt;BR /&gt;
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")&lt;BR /&gt;
Case Else&lt;BR /&gt;
If IsArray(Value) Then&lt;BR /&gt;
Dim List As Variant&lt;BR /&gt;
List = Value&lt;BR /&gt;
vlSet.funcall vSym, List&lt;BR /&gt;
Else&lt;BR /&gt;
vlSet.funcall vSym, Value&lt;BR /&gt;
End If&lt;BR /&gt;
End Select&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'populate a multiselect ListBox with Layer names&lt;BR /&gt;
Private Sub UserForm_Initialize()&lt;BR /&gt;
For Each Entry In ThisDrawing.Layers&lt;BR /&gt;
MultiListBox.AddItem Entry.Name&lt;BR /&gt;
Next&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'pass the selected layer names to the Lisp Variable "jb%MultiSelect"&lt;BR /&gt;
Private Sub OkButton_Click()&lt;BR /&gt;
Dim cnt As Integer&lt;BR /&gt;
cnt = MultiListBox.ListCount - 1&lt;BR /&gt;
SetLispVar "jb%MultiSelect", MultiListBox.Selected(cnt)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
(vlax-safearray-&amp;gt;list(vlax-variant-value jb%MultiSelect)) should return a&lt;BR /&gt;
list of the selected layer names.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts???&lt;BR /&gt;
&lt;BR /&gt;
thanks,&lt;BR /&gt;
&lt;BR /&gt;
jb&lt;/JDB&gt;</description>
      <pubDate>Mon, 26 Jun 2006 21:36:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687911#M33282</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-26T21:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: ListBox - MultiSelect</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687912#M33283</link>
      <description>Jeff,&lt;BR /&gt;
&lt;BR /&gt;
That's why (vlax-safearray-&amp;gt;list(vlax-variant-value jb%multiselect)) kept &lt;BR /&gt;
evaluating to :vlax-false - which was absolutely correct.  The VBA help led &lt;BR /&gt;
me to believe that if the multiselect property was set to true that &lt;BR /&gt;
MultiListBox.Selected returned an array already filled.  I had first thought &lt;BR /&gt;
that I might need to iterate through and test but my misreading led me &lt;BR /&gt;
astray.  Thanks for clarifying!!&lt;BR /&gt;
&lt;BR /&gt;
I'll get this yet.&lt;BR /&gt;
&lt;BR /&gt;
BTW - I'm compiling example code for Hybrid Applications over at &lt;BR /&gt;
theSwamp.org to help anyone who wants to transition from ObjectDCL over to &lt;BR /&gt;
VBA forms.  It doesn't look to promising for OBDC.  You'll probably see more &lt;BR /&gt;
like this in the near future.  Any help is always appreciated - I just wish &lt;BR /&gt;
I could reciprocate the favor!!!&lt;BR /&gt;
&lt;BR /&gt;
jb</description>
      <pubDate>Mon, 26 Jun 2006 23:42:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-multiselect/m-p/1687912#M33283</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-26T23:42:41Z</dc:date>
    </item>
  </channel>
</rss>

