Author Topic: How to read function parameters Using VbScript  (Read 9810 times)

SyedJunaid

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
How to read function parameters Using VbScript
« on: November 17, 2021, 10:45:24 pm »
         dim theMethod as EA.Method
         dim Ranges as EA.Method
         dim containers as EA.Method
         set theMethod = Repository.GetTreeSelectedObject()
         
         containers = theMethod.Notes
         
         Msgbox "The name of selected Method is: " & theMethod.Name
         
         Msgbox "Content in Notes ealier" & container
         
         
         
         'code for reading parameters
         dim str1 as EA.Method
         'dim str1 as EA.Parameter (used this line as well) commented now
         dim str2 as EA.Method
         'dim str2 as EA.Parameter (used this line as well) commented now
         
         dim temp as EA.Method
         set temp = Repository.GetTreeSelectedObject()
         dim catch as EA.Method
         'dim catch as EA.Parameter (used this line as well)  commented now
         catch = temp.Parameters.GetByName(str1.Name,str2.Name)

Input : FUNC(Std_ReturnType, CDD_XCP_CODE)

expected output: Std_ReturnType, CDD_XCP_CODE

Output:
getting this error:::::::::::::

object required: 'temp.parameter'
« Last Edit: November 17, 2021, 10:50:23 pm by SyedJunaid »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to read function parameters Using VbScript
« Reply #1 on: November 17, 2021, 11:05:19 pm »
Can you post minimal example with only the code you are trying to get to work, instead of a a bunch of code that is not relevant to the actual problem?

If the error states : object required: 'temp.parameter' and you are trying to using "temp.parameters" then there must be something wrong. Either you posted the wrong code, or the wrong error message.

A couple of remarks based on the code you posted

* str1 and str2 are not initialized (only declared), but you still somehow try to get their Name property. What do you expect to happen?
* GetByName() only accepts a single parameter, yet you try to pass two parameters
* if you want to get all parameters you can simply do a for each myParam on myMethod.Parameters

There is very little magic involved when writing code.

Geert




SyedJunaid

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to read function parameters Using VbScript
« Reply #2 on: November 17, 2021, 11:18:16 pm »
There is a function as mentioned below in project browser under a class as an operation

FUNC(Std_ReturnType, CDD_XCP_CODE)

I can get the function name using the code below :

dim theMethod as EA.Method
set theMethod = Repository.GetTreeSelectedObject()
Msgbox "The name of selected Method is: " & theMethod.Name

-------------------------------------------------------------------

The same way I want to get the function parameters, the code which I wrote is not working and is mentioned below:

dim str as EA.Method
dim theMethod as EA.Method
set theMethod = Repository.GetTreeSelectedObject()
Msgbox "The name of selected Method is: " & theMethod.Name

Msgbox "Parameters" & theMethod.Parameters.GetByName(str.Name)

Error Ouput: Object required : "theMethod.Parameters"

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to read function parameters Using VbScript
« Reply #3 on: November 17, 2021, 11:35:05 pm »
You are still trying to get property Name from an uninitialized variable str
The error you should be getting is Object required :''

But even if you try with a string, GetByName() is not supported on the Parameters collection.
So simply loop over the collection.

This works form me (if I have an operation selected in the project browser)

Code: [Select]
dim theMethod as EA.Method
set theMethod = Repository.GetTreeSelectedObject()
Msgbox "The name of selected Method is: " & theMethod.Name

dim parameter as EA.Parameter
for each parameter in theMethod.Parameters
Msgbox "Parameter.Name: " & parameter.Name
next

Geert

SyedJunaid

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to read function parameters Using VbScript
« Reply #4 on: November 18, 2021, 01:20:58 am »
Thank You soo much Geert, Now it works  :D

Regards,
Syed Junaid

SyedJunaid

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to read function parameters Using VbScript
« Reply #5 on: November 18, 2021, 04:12:24 pm »
Hi Geert,
              I think we will need to loop to store multiple parameters, i can see two seperate parameters in Msgbox and if I store in variable i can see the last variables , can you help me store multiple values in a variables as a string?

--------------------------------
input : FUNC(PARAM1, PARAM2)

dim param as EA.Parameter
dim parameter as EA.Parameter
for each parameter in theMethod.Parameters
param = parameter.Name
next
         
Msgbox "parameter: " & param

Observed Output: PARAM2

Expected Ouput: PARAM1, PARAM2

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to read function parameters Using VbScript
« Reply #6 on: November 18, 2021, 05:02:20 pm »
Maybe you should follow some kind of tutorial to get the basics of VBScript.

Geert