Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: [XM VBA] Accessing Dimension Note in VBA

$
0
0

[quote user="Michal Kurzewski"]as i run three way element getting[/quote]

The standard way (I don't know your current solution) is to have three separate "start methods" that take care about slightly different ways how to access data (model, fence, selection set). It allows to write clean code, because to scan model different construction is used (can define scan criteria) than to enumerate e.g. selection set (there is no scan criteria, so tests have to be implemented). But when elements are filtered in enumeration, all methods call the same function to process note cell. And I guess to test if the cell is note cell or not the code should be split into separate methods.

[quote user="Michal Kurzewski"]i never used this before, as i had no reason.[/quote]

Read DLong type explanation in MicroStation VBA help. It's MicroStation specifc type, so it cannot be used with standard VBA functions. You should always use DLong for element id and never (!) to convert it into another type (e.g. long) if not really necessary (to display is probably the only case). And the converted result should not be treated as valid for further processing.

Because of this reason your code is invalid: Despite of it's very rare, it's not ensured  that it will be possible to convert DLong to Long.

[quote user="Michal Kurzewski"]c = c + 1[/quote]

What is a meaning of that? I can guess only, but if you use c as element id to get next element, it's bad idea. If you want to move to the next element, use enumerator. You current code (if c used as element id):

  • Will crash if you will receive old design file with very high element ids that cannot be converted from 64bit number (DLong) to 32bit number (Long). A probability of such situation is very small, but why to write bad dirty unstable code?
  • Will also crash if an element with c+1 id will not exists. It's not ensured, it's just id, not sequence counter.

Why to don't use a standard way how to work with cell content?

If oElm.Type = msdElementTypeCellHeader Then
    Dim cellContentEnumerator As ElementEnumerator
    Set cellContentEnumerator = oElm.AsCellElement.GetSubElements
ProcessCellContent cellContentEnumerator ' Process a cell content in your custom method End If

If you really need to increase DLong value (but I have to say I am really curious why), use DLongAdd method to realize DLong + 1 operation without converting DLong to smaller type.

With regards,

  Jan


Viewing all articles
Browse latest Browse all 7260

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>