Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA autocad help 1

Status
Not open for further replies.

d7secs

Technical User
Oct 26, 2007
2
US
Hi everyone,
I have recently started to delve into VBA along with Autocad He is my beginner code that should count blocks in an autocad drawing. However, only the block names are placed in ListBox1 and a 0 count for all of them in ListBox2.
Can anyone see a reason?

Sub CommandButton1_Click()
Dim i, j, btot As Integer
Dim bnam As String
Dim ent As Object
btot = ThisDrawing.Blocks.Count

For i = 0 To btot - 1
bnam = ThisDrawing.Blocks.Item(i).Name
If Not Mid$(bnam, 1, 1) = "*" Then ListBox1.AddItem bnam
Next i

For i = 0 To ListBox1.ListCount - 1
bnam = ListBox1.List(i): btot = 0
For j = 0 To ThisDrawing.ModelSpace.Count - 1
Set ent = ThisDrawing.ModelSpace.Item(j)
If ent.EntityType = acBlockReference And ent.Name = banam Then btot = btot + 1
Next j
ListBox2.AddItem btot
Next i
End Sub
 
Probably get better help in the VBA forum - this is VB 5/6.

Always remember that you're unique. Just like everyone else.
 
Two things.

<Dim i, j, btot As Integer
You can't do this in VB. i and j are variants here, btot is the only integer. You have to say
<Dim i as Integer, j as integer, btot as integer

To make them all integers.

< If ent.EntityType = acBlockReference And ent.Name = banam
It's clear that this is never true. I would suggest you set a breakpoint on this line and get a look at what the properties are every time you hit this line. You'll probably figure out what's wrong.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top