Looping through attributes

Looping through attributes

Anonymous
Not applicable
420 Views
5 Replies
Message 1 of 6

Looping through attributes

Anonymous
Not applicable
Hi there. Let me try to explain what's my problem.

I've inserted a block with attributes in the drawing. The names (TagString)
of the attributes are written in the following format DAN1, DAN2, DAN3, ....
Now what I'm trying to do is make an array of all attribute references and
then loop through them until I find the one I'm looking for and then change
it's value (TextString) to a certain date that is written in textbox.



I thought that if I write a code like this all the attributes with the name
DAN + something should be assigned a value of Datum variable. But nothing
happens.

---------------------------------------------------------------

Public Sub IzpisiDan()



Dim Datum As Variant

Dim objAttRef As AcadAttributeReference

Dim varAttributes As Variant

Dim intAttLoop As Integer

Dim intSteviloDni As Integer

Dim intI As String

Dim Dan As String



Datum = Format(txtDatumStart.Text, "dd.mm.")

intI = 0

varAttributes = objHarm.GetAttributes



For intAttLoop = LBound(varAttributes) To UBound(varAttributes)

intI = intI + 1

Dan = "DAN" & intI

Set objAttRef = varAttributes(intAttLoop)

If objAttRef.TagString = Dan Then

objAttRef.TextString = Datum

End If

Next

ThisDrawing.Application.Update



End Sub
---------------------------------------------------------------
But if I change that loop that it looks only for a specific attribute it
works.
---------------------------------------------------------------
For intAttLoop = LBound(varAttributes) To UBound(varAttributes)

intI = 1

Dan = "DAN" & intI

Set objAttRef = varAttributes(intAttLoop)

If objAttRef.TagString = Dan Then

objAttRef.TextString = Datum

End If

Next

---------------------------------------------------------------

If anyone knows what I'm doing wrong or if you have a better idea how to do
that task please let me know.



Thank you.

Marko
0 Likes
421 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
This is off the top of my head.....

Public Sub IzpisiDan()

Dim Datum As Variant
Dim objAttRef As AcadAttributeReference
Dim varAttributes As Variant
Dim intSteviloDni As Integer

Datum = Format(txtDatumStart.Text, "dd.mm.")

varAttributes = objHarm.GetAttributes

'*******just for each your way through the array************
for each objAttRef in varAttributes
if objAttRef.tagstring like "dan*" then
objAttRef.TextString = Datum
end if
next objAttRef

End Sub
--
"Make the most of the best
and the least of the worst."
Robert Louis Stevenson

http://www.acadx.com
0 Likes
Message 3 of 6

Anonymous
Not applicable
To the best of my knowledge, you can't use For Each
on arrays.

Your code seems fine, except that you should use
the Like operator to test the variable.

If objAttRef.TagString Like "dan*" Then ....


"Marko Rogic" wrote in message
news:728880B2AB60406CD563292C975073DD@in.WebX.maYIadrTaRb...
> Hi there. Let me try to explain what's my problem.
>
> I've inserted a block with attributes in the drawing. The names
(TagString)
> of the attributes are written in the following format DAN1, DAN2, DAN3,
....
> Now what I'm trying to do is make an array of all attribute references and
> then loop through them until I find the one I'm looking for and then
change
> it's value (TextString) to a certain date that is written in textbox.
>
>
>
> I thought that if I write a code like this all the attributes with the
name
> DAN + something should be assigned a value of Datum variable. But nothing
> happens.
>
> ---------------------------------------------------------------
>
> Public Sub IzpisiDan()
>
>
>
> Dim Datum As Variant
>
> Dim objAttRef As AcadAttributeReference
>
> Dim varAttributes As Variant
>
> Dim intAttLoop As Integer
>
> Dim intSteviloDni As Integer
>
> Dim intI As String
>
> Dim Dan As String
>
>
>
> Datum = Format(txtDatumStart.Text, "dd.mm.")
>
> intI = 0
>
> varAttributes = objHarm.GetAttributes
>
>
>
> For intAttLoop = LBound(varAttributes) To
UBound(varAttributes)
>
> intI = intI + 1
>
> Dan = "DAN" & intI
>
> Set objAttRef = varAttributes(intAttLoop)
>
> If objAttRef.TagString = Dan Then
>
> objAttRef.TextString = Datum
>
> End If
>
> Next
>
> ThisDrawing.Application.Update
>
>
>
> End Sub
> ---------------------------------------------------------------
> But if I change that loop that it looks only for a specific attribute it
> works.
> ---------------------------------------------------------------
> For intAttLoop = LBound(varAttributes) To
UBound(varAttributes)
>
> intI = 1
>
> Dan = "DAN" & intI
>
> Set objAttRef = varAttributes(intAttLoop)
>
> If objAttRef.TagString = Dan Then
>
> objAttRef.TextString = Datum
>
> End If
>
> Next
>
> ---------------------------------------------------------------
>
> If anyone knows what I'm doing wrong or if you have a better idea how to
do
> that task please let me know.
>
>
>
> Thank you.
>
> Marko
>
>
>
0 Likes
Message 4 of 6

Anonymous
Not applicable
Actually as of VB6, I don't know about earlier versions, you can...with some
caveats. The element of the for each...next must be a variant. Also, the
element is passed by value. This case doesn't demonstrate it well, but I
can see where this could cause some serious logical errors causing one to
pull out large quantities of hair.

So Marko, while my for each...next suggestion is technically feasible, I
can't really say that it's advisable. Keep your for...next loop. Good
luck.
--
"Make the most of the best
and the least of the worst."
Robert Louis Stevenson

http://www.acadx.com
0 Likes
Message 5 of 6

Anonymous
Not applicable
> Actually as of VB6,

For Each works with arrays in VBA5 as well.

--
Learn to think outside the book.

http://www.acadx.com


"Bobby C. Jones" wrote in message
news:C552750852B1400F393A57EB5E9BB47D@in.WebX.maYIadrTaRb...
> Actually as of VB6, I don't know about earlier versions, you can...with
some
> caveats. The element of the for each...next must be a variant. Also,
the
> element is passed by value. This case doesn't demonstrate it well, but I
> can see where this could cause some serious logical errors causing one to
> pull out large quantities of hair.
>
> So Marko, while my for each...next suggestion is technically feasible, I
> can't really say that it's advisable. Keep your for...next loop. Good
> luck.
> --
> "Make the most of the best
> and the least of the worst."
> Robert Louis Stevenson
>
> http://www.acadx.com
>
>
>
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks for your input people, I'll try your suggestions ASAP.

Marko.

"Frank Oquendo" wrote in message
news:32CDAF0820F6160D057F410DB9AA64BB@in.WebX.maYIadrTaRb...
> > Actually as of VB6,
>
> For Each works with arrays in VBA5 as well.
>
> --
> Learn to think outside the book.
>
> http://www.acadx.com
>
>
> "Bobby C. Jones" wrote in message
> news:C552750852B1400F393A57EB5E9BB47D@in.WebX.maYIadrTaRb...
> > Actually as of VB6, I don't know about earlier versions, you can...with
> some
> > caveats. The element of the for each...next must be a variant. Also,
> the
> > element is passed by value. This case doesn't demonstrate it well, but
I
> > can see where this could cause some serious logical errors causing one
to
> > pull out large quantities of hair.
> >
> > So Marko, while my for each...next suggestion is technically feasible, I
> > can't really say that it's advisable. Keep your for...next loop. Good
> > luck.
> > --
> > "Make the most of the best
> > and the least of the worst."
> > Robert Louis Stevenson
> >
> > http://www.acadx.com
> >
> >
> >
>
>
0 Likes