ListBox - MultiSelect

ListBox - MultiSelect

Anonymous
Not applicable
426 Views
2 Replies
Message 1 of 3

ListBox - MultiSelect

Anonymous
Not applicable
This should work, right?

'SetLispVar provided by Tony Tanzillo
Public Sub SetLispVar(Symbol As String, Value)
Dim vlapp As Object
Dim vlFuncs As Object
Dim vlSet As Object
Dim vSym
Set vlapp = CreateObject("Vl.Application.16")
Set vlFuncs = vlapp.ActiveDocument.Functions
Set vSym = vlFuncs.Item("read").funcall(Symbol)
Set vlSet = vlFuncs.Item("set")
Select Case VarType(Value)
Case vbByte, vbInteger, vbLong
Dim lVal As Long
lVal = Value
vlSet.funcall vSym, lVal
Case vbString
Dim strVal As String
strVal = Value
vlSet.funcall vSym, strVal
Case vbDouble
Dim dblVal As String
dblVal = Value
vlSet.funcall vSym, dblVal
Case vbEmpty
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")
Case Else
If IsArray(Value) Then
Dim List As Variant
List = Value
vlSet.funcall vSym, List
Else
vlSet.funcall vSym, Value
End If
End Select
End Sub

'populate a multiselect ListBox with Layer names
Private Sub UserForm_Initialize()
For Each Entry In ThisDrawing.Layers
MultiListBox.AddItem Entry.Name
Next
End Sub

'pass the selected layer names to the Lisp Variable "jb%MultiSelect"
Private Sub OkButton_Click()
Dim cnt As Integer
cnt = MultiListBox.ListCount - 1
SetLispVar "jb%MultiSelect", MultiListBox.Selected(cnt)
End Sub

(vlax-safearray->list(vlax-variant-value jb%MultiSelect)) should return a
list of the selected layer names.

Any thoughts???

thanks,

jb
0 Likes
427 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
MultiListBox.Selected(cnt)
This just returns a Boolean value of whether the ListBox Item at the cnt
index is selected.

You use this to iterate the ListBox items and determine if an item has been
selected.

This does what you were expecting:
Private Sub OkButton_Click()
Dim cnt As Integer
Dim aSelctd() As String
Dim I As Integer

ReDim aSelctd(0 To MultiListBox.ListCount - 1)
For cnt = 0 To MultiListBox.ListCount - 1
If MultiListBox.Selected(cnt) = True Then
aSelctd(I) = MultiListBox.List(cnt)
I = I + 1
End If
Next
ReDim Preserve aSelctd(0 To I - 1)
SetLispVar "jb%MultiSelect", aSelctd
End Sub

"James Buzbee" wrote in message
news:5219172@discussion.autodesk.com...
This should work, right?

'SetLispVar provided by Tony Tanzillo
Public Sub SetLispVar(Symbol As String, Value)
Dim vlapp As Object
Dim vlFuncs As Object
Dim vlSet As Object
Dim vSym
Set vlapp = CreateObject("Vl.Application.16")
Set vlFuncs = vlapp.ActiveDocument.Functions
Set vSym = vlFuncs.Item("read").funcall(Symbol)
Set vlSet = vlFuncs.Item("set")
Select Case VarType(Value)
Case vbByte, vbInteger, vbLong
Dim lVal As Long
lVal = Value
vlSet.funcall vSym, lVal
Case vbString
Dim strVal As String
strVal = Value
vlSet.funcall vSym, strVal
Case vbDouble
Dim dblVal As String
dblVal = Value
vlSet.funcall vSym, dblVal
Case vbEmpty
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")
Case Else
If IsArray(Value) Then
Dim List As Variant
List = Value
vlSet.funcall vSym, List
Else
vlSet.funcall vSym, Value
End If
End Select
End Sub

'populate a multiselect ListBox with Layer names
Private Sub UserForm_Initialize()
For Each Entry In ThisDrawing.Layers
MultiListBox.AddItem Entry.Name
Next
End Sub

'pass the selected layer names to the Lisp Variable "jb%MultiSelect"
Private Sub OkButton_Click()
Dim cnt As Integer
cnt = MultiListBox.ListCount - 1
SetLispVar "jb%MultiSelect", MultiListBox.Selected(cnt)
End Sub

(vlax-safearray->list(vlax-variant-value jb%MultiSelect)) should return a
list of the selected layer names.

Any thoughts???

thanks,

jb
0 Likes
Message 3 of 3

Anonymous
Not applicable
Jeff,

That's why (vlax-safearray->list(vlax-variant-value jb%multiselect)) kept
evaluating to :vlax-false - which was absolutely correct. The VBA help led
me to believe that if the multiselect property was set to true that
MultiListBox.Selected returned an array already filled. I had first thought
that I might need to iterate through and test but my misreading led me
astray. Thanks for clarifying!!

I'll get this yet.

BTW - I'm compiling example code for Hybrid Applications over at
theSwamp.org to help anyone who wants to transition from ObjectDCL over to
VBA forms. It doesn't look to promising for OBDC. You'll probably see more
like this in the near future. Any help is always appreciated - I just wish
I could reciprocate the favor!!!

jb
0 Likes