I hate spending time correcting AI-generated code, but the first thing that sticks out is that the following:
(setq attArray (vla-getattributes vlaBlock))
Will return a safearray variant, which cannot be iterated directly using foreach.
Instead, you can use:
(setq attArray (vlax-invoke vlaBlock 'getattributes))
Which will return the data using native data types, i.e. a list.
You can find more examples here.