Book a Demo

Author Topic: Compare a Diagram Name in vbs  (Read 4014 times)

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Compare a Diagram Name in vbs
« on: April 05, 2017, 10:57:36 pm »
Hi,

I´m trying to compare two strings with each other, but it does not work : /

First of all the Code:


option explicit
!INC Local Scripts.EAConstants-VBScript

sub HidePrivateAttributes()
   
   ' Get the type of element selected in the Project Browser
   dim treeSelectedType
   treeSelectedType = Repository.GetTreeSelectedItemType()
   
   select case treeSelectedType

      case otDiagram
         ' Code for when a diagram is selected
         
         dim theDiagram as EA.Diagram
         set theDiagram = Repository.GetTreeSelectedObject()
         dim Ops               
         dim Atts

         

         Atts = theDiagram.Name Like "XXX Attributes*"
         Ops = theDiagram.Name Like "XXX Operations*"
         
         If Atts = true then
         call hideAtt(theDiagram)
         Elseif Ops = true then
         call hideOps(theDiagram)
         Else
         End if


         ReloadDiagram(theDiagram.DiagramID)

      
      case else
         ' Error message
         Session.Prompt "This script does not support items of this type.", promptOK
         
   end select
   
end sub

Function hideAtt(diagram)
         diagram.ShowPrivate(false)
         diagram.Update()
End Function

Function hideOps(diagram)
         diagram.ShowPublic(false)
         diagram.Update()
End Function



But it seems that Sparx don´t like the "LIKE" Operator or I use it wrong.
Based on msdn homepage it is the correct syntax "result = string Like pattern  "

I tryed to use "Option Compare Binary/Text" but it send me an error "Statement expected"

I Know I'm lacking knowledge in VBS and it might be a simple VBS failure.

I search the web for tutorials but it all scripts it is no problem to use this operator.

Please maybe someone can explain this to me.

regards

Benny


« Last Edit: April 05, 2017, 11:25:40 pm by Benny »

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Compare a Diagram Name in vbs
« Reply #1 on: April 05, 2017, 11:04:03 pm »
Hi,

ok one minute after I posted this i found, that "LIKE" is not available in VBS  :'(


I did it with instr()

=============================================

         Atts=instr(1,theDiagram.Name,"XXX Attributes",0)
         
         Ops=instr(1,theDiagram.Name,"XXX Operations",0)
         
         If Atts = 1 then
         'call hideAtt(theDiagram)
         msgBox(Atts)
         Elseif Ops = 1 then
         msgBox(Ops)
         'call hideOps(theDiagram)
         Else
         End if
=====================================================

Yeah  ;D now I can move on.
« Last Edit: April 05, 2017, 11:31:21 pm by Benny »