Listbox multiselect

Listbox multiselect

Anonymous
Not applicable
231 Views
1 Reply
Message 1 of 2

Listbox multiselect

Anonymous
Not applicable
Hopefully someone can help me. I am trying to insert a bunch of user picked symbol blocks into a drawing. I populate a listbox from a text file that contains all of our symbols. I then allow the user to select multiple symbols to be inserted into the drawing. Each symbol block is labeled SYM##. The text file that populates the listbox is in numeric order. So for example, if the user wants to insert our symbol heading and our high pressure steam symbol, these are 1 and 4 in the symbol list. So, the list index should return 1 and 4 to be inserted into the drawing. My program works fine if only 1 listbox item is selected, but if multiple items are selected, the list index returns only 1 number the whole time. I have copied part of my program below. I realize that I probably haven't explained this very well, so if you have any questions, please feel free to ask. Any help would be greatly appreciated.

Private Sub UserForm_Activate()
Dim Symbol(8) As String
Dim Count As Integer
Dim fh
Dim tmp

fh = FreeFile
Open CustomToolbar & "symbols.txt" For Input As #fh

Do While Not EOF(fh)
Line Input #fh, tmp
lstSymbolList.AddItem tmp
Loop
Close fh
End Sub

Private Sub cmdAddSymbols_Click()
frmSymbols.Hide
Dim Count As Integer
Dim ItemNo As Long
Dim Y

With ThisDrawing
varInsPnt = .Utility.GetPoint(, "Select Insertion point: ")
Y = varInsPnt(1)

For Count = 0 To lstSymbolList.ListCount - 1
If lstSymbolList.Selected(Count) = True Then
ItemNo = lstSymbolList.ListIndex
Debug.Print ItemNo
If ItemNo < 10 Then
strblock = "SYM" & "0" & ItemNo
Else
strblock = "SYM" & ItemNo
End If

varInsPnt(1) = Y
MsgBox (strblock & vbCr & vbCr & varInsPnt(0) & vbCr & varInsPnt(1))
Set NewBlk = .ModelSpace.InsertBlock(varInsPnt, strblock, 1, 1, 1, 0)
Y = Y - 0.25
End If
Next
lstSymbolList.Clear
End With
End Sub
0 Likes
232 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
If the name is the block just grab that instead.
I assume your blocks are the list names not the
index number.

If ListBox1.Selected(i) Then
msgString = msgString & vbCrLf & ListBox1.List(i)
End If

wrote in message news:4921376@discussion.autodesk.com...
Hopefully someone can help me. I am trying to insert a bunch of user picked
symbol blocks into a drawing. I populate a listbox from a text file that
contains all of our symbols. I then allow the user to select multiple
symbols to be inserted into the drawing. Each symbol block is labeled
SYM##. The text file that populates the listbox is in numeric order. So for
example, if the user wants to insert our symbol heading and our high
pressure steam symbol, these are 1 and 4 in the symbol list. So, the list
index should return 1 and 4 to be inserted into the drawing. My program
works fine if only 1 listbox item is selected, but if multiple items are
selected, the list index returns only 1 number the whole time. I have
copied part of my program below. I realize that I probably haven't
explained this very well, so if you have any questions, please feel free to
ask. Any help would be greatly appreciated.

Private Sub UserForm_Activate()
Dim Symbol(8) As String
Dim Count As Integer
Dim fh
Dim tmp

fh = FreeFile
Open CustomToolbar & "symbols.txt" For Input As #fh

Do While Not EOF(fh)
Line Input #fh, tmp
lstSymbolList.AddItem tmp
Loop
Close fh
End Sub

Private Sub cmdAddSymbols_Click()
frmSymbols.Hide
Dim Count As Integer
Dim ItemNo As Long
Dim Y

With ThisDrawing
varInsPnt = .Utility.GetPoint(, "Select Insertion point: ")
Y = varInsPnt(1)

For Count = 0 To lstSymbolList.ListCount - 1
If lstSymbolList.Selected(Count) = True Then
ItemNo = lstSymbolList.ListIndex
Debug.Print ItemNo
If ItemNo < 10 Then
strblock = "SYM" & "0" & ItemNo
Else
strblock = "SYM" & ItemNo
End If

varInsPnt(1) = Y
MsgBox (strblock & vbCr & vbCr & varInsPnt(0) & vbCr &
varInsPnt(1))
Set NewBlk = .ModelSpace.InsertBlock(varInsPnt, strblock, 1, 1,
1, 0)
Y = Y - 0.25
End If
Next
lstSymbolList.Clear
End With
End Sub
0 Likes