Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Creating functions
Topic Summary:
Created On: 17-Aug-2005 16:26
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Chris Jones, on Wednesday, August 17, 2005 9:18 PM

Answer:
There sure is. It is, in fact, just like in C/C++.....here's an example:

int numObjects(string mod_name) {
//code for your function...
}


Then to call it:

int objs = numObjects("/Products/product1")


-Chris
 17-Aug-2005 16:26
User is offline View Users Profile Print this message


Brian Jackson

Posts: 10
Joined: 2-Aug-2005

Is there a way to create functions in DXL scripts? I have some code I wrote in DXL and want desperately like to create a function/subroutine that I could call in the body of my "main" program (like one would do in C/C++ programs). I would need to pass parameters (arguments) to my function when I make a function call. 
Report this to a Moderator Report this to a Moderator
 17-Aug-2005 17:23
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

Answer Answer
There sure is. It is, in fact, just like in C/C++.....here's an example:

int numObjects(string mod_name) {
//code for your function...
}


Then to call it:

int objs = numObjects("/Products/product1")


-Chris
Report this to a Moderator Report this to a Moderator
 19-Aug-2005 21:52
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Functions with no parameters still need to have the parenthesis () when declared. Functions that don't return a value are declared as type "void" (perhaps these are called "subroutines"). Those that have neither had better be updating a global variable, such as this:

int g_NumCalls = 0

void UpdateNumCalls()
{ g_NumCalls++
}

UpdateNumCalls
UpdateNumCalls() // Its better to use empty parens when calling parameterless functions
// ... it makes understanding its a function easier when reading, and there are times
// .... when it really matters.
print g_NumCalls "\n" // prints "2"

Functions with a return value had better set that value in each "return" statement, such as "return(i)".

The calling Main program does NOT have to use the return value. if UpdateNumCalls returns the number of calls so far, the Main can still do this: "UpdateNumCalls()" and the returned integer is ignored.

- Louie
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.