Hi David,
Here is the code as it is currently. Just to warn you... It's pretty long.
Basically, it goes through, has the user select a roomtag block, change the
attribute value to the textbox value the user entered, adds one to the Cnt
variable and then does the next one the user selects. The first tag works
fine, but after that the Cnt value changes (somehow) and then it leaves out
the necessary 0's (zeros). I can't figure this out. Any guesses?
Private Sub cmdRun_Click()
Dim fType, fData, ss As AcadSelectionSet
Dim varBlkattribs As Variant
Dim strBlkAttribs As String
Dim blkRef As AcadBlockReference
Dim objBlkSelect As AcadSelectionSet
Dim intarray() As Integer
Dim attarry As AcadAttribute
Dim Point(0 To 2) As Double
Dim strArray As String
Dim Acadblock As AcadBlockReference
Dim Ent As AcadEntity
Dim Pt As Variant
Dim Cnt As Variant 'or Integer (variant works better)
Dim rnum As String
Dim rnum2 As String
Dim Rnum3 As Variant
Dim endResult As String
Dim optcomp As String
'Set a filter to search for all instances of the "Roomtag" block and apply
the count to the ss 'variable.
With ThisDrawing.Utility
Set ss = CreateSelectionSet()
BuildFilter fType, fData, 0, "INSERT", 2, "ROOMTAG"
ss.Select acSelectionSetAll, , , fType, fData
'Prompt the user as to how many roomtags there are in the drawing.
.Prompt vbCr & "There are " & ss.Count & " Roomtags in this drawing."
End With
'hide the form
Me.Hide
'If the first letter in the textbox is an "A" then do the following
If Left(txtStrtNum.Text, 1) = LCase("A") Then
rnum2 = txtStrtNum.Text
Cnt = Format(Mid$(rnum2, 2), "000")
rnum = Mid$(rnum2, 1, 1)
endResult = UCase(rnum) & Cnt
On Error Resume Next
If ss.Count > 0 Then
Do
'Have the user select the tags in order and udate them as they are
selected.
ThisDrawing.Utility.GetEntity Ent, Pt, "Select the roomtags in
order: "
Ent.Highlight True
If Err Then
If ThisDrawing.GetVariable("errno") = "7" Then
Err.Clear
Else
Err.Clear
Exit Do
End If
End If
'check to see if the entity selected is a block
If TypeOf Ent Is AcadBlockReference Then
Set blkRef = Ent
'check to see if the block is named "Roomtag"
If blkRef.Name = "ROOMTAG" Then
'Check to see if the roomtag has attributes.
If blkRef.HasAttributes Then
varBlkattribs = blkRef.GetAttributes
varBlkattribs(0).TextString = endResult
End If
End If
'add 1 (one) to each roomtag as each one is selected.
Cnt = Cnt + 1
endResult = UCase(rnum & (Cnt))
Else
'If the entity selected is not a roomtag block then send the
following message.
MsgBox "The Object You Selected Is Not A Roomtag."
End If
Ent.Highlight False
Loop
End If
Ent.Highlight False
'If there is no value "A" in the textbox, then do the folowing:
'The folowing section works with no problems.
Else
Cnt = txtStrtNum.Text
End If
On Error Resume Next
If ss.Count > 0 Then
Do
'Have the user select the tags in order and udate them as they are
selected.
ThisDrawing.Utility.GetEntity Ent, Pt, "Select the roomtags in
order: "
Ent.Highlight True
If Err Then
If ThisDrawing.GetVariable("errno") = "7" Then
Err.Clear
Else
Err.Clear
Exit Do
End If
End If
'check to see if the entity selected is a block
If TypeOf Ent Is AcadBlockReference Then
Set blkRef = Ent
'check to see if the block is named "Roomtag"
If blkRef.Name = "ROOMTAG" Then
'Check to see if the roomtag has attributes.
If blkRef.HasAttributes Then
varBlkattribs = blkRef.GetAttributes
varBlkattribs(0).TextString = Cnt
End If
End If
'add 1 (one) to each roomtag as each one is selected.
Cnt = Cnt + 1
Else
'If the entity selected is not a roomtag block then send the
following message.
MsgBox "The Object You Selected Is Not A Roomtag."
End If
Ent.Highlight False
Loop
End If
Ent.Highlight False
End Sub
Thanx in advance for any suggestions you may have.
Rob
"David Moroni" wrote in message
news:396F057CD9704DA571DF6A05834A8E4D@in.WebX.maYIadrTaRb...
> Hi Rob,
>
> Your code has probably gone through several changes since you first
> posted your question. Could you post your procedure with the latest
> changes? This might help diagnose the problem.
>
> David
>