cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB Script and object

lardybenoit
New Contributor

Dear all,

 

I would need to assign via a VB Script a level of risk (sRisk) which is an existing object with some values:

- Low/Medium/High

to an application (ApplicationName).

I get an error on type ojbect assigned to the method is not the right one.

 

Do someone could help me to bring the adequat modifications?

 

Thanks

 

Here is the code:

 

sAppName = "ApplicationName"

sRisk = "Medium"

'Get application collection

Set oAppli = lApplis.Item(sAppName)

'Quality test

sEmpty = oAppli.GetID

If sEmpty > 0 Then

     ctr = oAppli.GetCollection("Risque").Count

     If (ctr > 0) Then

                    For Each oItem In oAppli.GetCollection("Risque")

                        oItem.Remove

                    Next

     End If

     'Get Risk collection

     Set oRisk = lRisks.Item(sRisk)

               

     'Set the reference of the risk to the application and remove the existing ones

     oAppli.GetCollection("Risque").Add (oRisk.GetID)

End If

...

1 Reply

lionel
MEGA
MEGA

Hello Benoit,

 

First of all, since id's can be negative numbers, you should write

If sEmpty <> 0 Then

 instead of

If sEmpty > 0 Then

 

Then, the way you remove your risks from your application will not work (if you have many risks for your application, it will remove only half of them 🙂 You should do it this way :

Set colRisques = oAppli.getCollection("Risque")
For i = colRisques.count to 1 Step -1
  colRisques.item(i).Remove
Next

 

Then, concerning your direct question, you should write it this way ("oRisk" must have been defined before in your script) :

Dim oRisque
Set oRisque = oAppli.GetCollection("Risque").Add (oRisk)

 I hope that helps.

 

Regards,

 

Lionel