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

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

I'm not good enough to get mad at myself
 

Add:

Option Explicit

at the very top of your code, and Run it. You will find out that you did not declare banam


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top