Book a Demo

Author Topic: How to check for object type within script?  (Read 3349 times)

Asperamanca

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
How to check for object type within script?
« on: September 25, 2012, 09:43:01 pm »
I would like to extend an existing and working "replace name in package" script to also replace the string in the code generation filename.

Naturally, not all objects the script might encounter have the corresponding GenFile property. How do I check whether an object has the property, so the script does not run into an error?

I have tried the following:

Code: [Select]
     'replace string in Filename
      If (obj.ObjectType = otElement) Then
            If InStr(obj.GenFile, LCase(fromString)) > 0 Then
               obj.GenFile = Replace(obj.GenFile, LCase(fromString), LCase(toString))
               modified = True
            End If
      End If

However, I get the error: "Variable undefined: otElement"

Ideas?

Asperamanca

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: How to check for object type within script?
« Reply #1 on: September 25, 2012, 09:49:54 pm »
Found a somewhat ugly workaround:

Code: [Select]
     'replace string in Filename
      Dim strGenFile
      strGenFile = ""
      On Error Resume Next
      strGenFile = obj.GenFile
      On Error Goto 0
      If InStr(strGenFile, LCase(fromString)) > 0 Then
         strGenFile = Replace(strGenFile, LCase(fromString), LCase(toString))
         obj.GenFile = strGenFile
         modified = True
      End If