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

RE: [V8i VBA] Check if a model already exists

$
0
0

Hi Barry,

I agree with Jon that it's not approach to use LIKE comparison, because what you need is exact case insensitive string comparison, not comparing strings using pattern. And if you prefer to use LIKE, you have to know well how this operation works.

What I also don't like in your code is to do test and to do action at the same place. It's bad coding habbit and always lead to not clear code.

I prefer to separate the model existence testing into own function:

Private Function DoesModelExist(modelName As String) As Boolean
    DoesModelExist = False
    Dim model As ModelReference
    
    For Each model In ActiveDesignFile.Models
        If (0 = StrComp(model.Name, modelName, vbTextCompare)) Then
            DoesModelExist = True
            Exit Function
        End If
    Next
End Function

So you can just ask for the test later and the code is very clear:

Public Sub TestModelExists()
    Dim modelName As String
    modelName = "my new model name"
    
    If (False = DoesModelExist(modelName)) Then
        ' create your model
    End If
End Sub

With regards,

 Jan


Viewing all articles
Browse latest Browse all 7260

Trending Articles



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