Passing a table name to a function

Discussions about tabulating data in the designer or in batch mode
Post Reply
hraggers

Passing a table name to a function

Post by hraggers »

Is there a way to pass a table name as "t1101" below to a function?

Code: Select all

 crosstab float(1) t1101 chage2+sex2+pinter2+bsize+mothstat+mothbmi+v102w+{}V101+v106w+s_educ2+v190w+total
                                             hghtage+wghthght+wghtage+numchild
    exclude(rowzero,colzero,totals,percents,specval)
    title( "Table 11.1  Nutritional status of children"," ",
           "Percentage of children under five years classified as",
           "malnourished according to three anthropometric indices of",
           "nutritional status: height-for-age, weight-for-height, and",
           "weight-for-age, by background characteristics, Countryxxxx" )
     stub( "Background characteristic" );
The number of times t1101 above needs to be tallied depends on the variable {}V101, which represents region. This variable will be set "on the fly" and depends on the survey I'm looking at. It may be once, it may be more often, depending on the level of aggregation that is required. Therefor I need a function. Currently I'm passing a string in my function call. For example in a function called TxTab():

Code: Select all

TxTab("t1101", rweight)
In the TxTab() function I then decide, depending on the string passed, which table needs to be tallied and how often (if more than once all other row variables must be set to not applicable):

For example:

Code: Select all

function Txtab( alpha(15) TabName, tabweight )
  
   
    do tally_t = 0 while tally_t <= tally_n
      
      if tally_t then 
        s_region(tally_t,xregion);
      endif;
       
      if         strip(TabName) = "t1101"     then xtab( t1101,   tabweight )
      elseif   strip(TabName) = "t1102"     then xtab( t1102,   tabweight )
      etc....

      ............
      ...........
end;
I do have a few hundred of these calls in my program so It would really help if I could pass the table name and then just do something like:

Code: Select all

TxTab(Tab_Name, rweight)
with

Code: Select all

function Txtab( TableName, tabweight )
  
    do tally_t = 0 while tally_t <= tally_n
      
      if tally_t then 
        s_region(tally_t,xregion);   // sets applicable row variables to not applicable
      endif;
      
      xtab( TableName, tabweight );
    enddo;
    if tally_n then s_region(0,xregion) endif;  // resets the row variables
end;
      


Thanks for your help.

Han.
p_w

Re: Passing a table name to a function

Post by p_w »

Getvalue Function

Formats:
d = getvalue(alpha-expression[,numeric-expressions]);
d = getvaluenumeric(alpha-expression[,numeric-expressions]);
s = getvaluealpha(alpha-expression[,numeric-expressions]);

Description:

The getvalue function returns the value of a variable when the variable name is not known at compilation time (when writing the application). The function searches for the first parameter alpha-expression and then returns the value of a variable with that name, if found. Getvalue and getvaluenumeric return the value of numeric variables. Getvaluealpha returns the value of an alpha variable. Optional parameters allow you to pass occurrence numbers to the function.

Return value:

The function returns the variable's value if the variable name was found. If a numeric variable was not found, the functions getvalue and getvaluenumeric return DEFAULT. If an alpha variable was not found, getvaluealpha returns a blank string.

Examples:
errmsg("The current field's value is %d",getvalue(getsymbol()));
Post Reply