Sequence function and passing variables


Recommended Posts

I'm having trouble with passing variables to a sequence used as a function.

sequence code is

define EDIT_RECIPE_WIDTH = 376
define EDIT_RECIPE_HEIGHT = 290

define EDIT_RECIPE_TABLE_ROW_HEIGHT = 20

function EditRecipeDialog(RecipeNum)
   private PosX = 100
   private PosY = 100
   private Result = 0
   private index

	  if(!argc)
		 //RecipeNum = 99	  // doesn't work
		 private RecipeNum = 99	  // works
	  else
		 private pArr = Recipe[RecipeNum]
		 for (index = 0, index < NumRows(pArr.Ratio), index++)
			TmpRecipe.Ratio[index] = pArr.Ratio[index]
		 endfor	  
	  endif

// do other stuff ...

return

// end sequence

I originally did not have the private declaration for RecipeNum when setting to 99, however the sequence/function wouldn't work unless I declared the variable. Before adding the private declaration I watched the variable RecipeNum, and stepped through the function, but it never changed from "C1000 channel or function not found", even after being set to 99.

I have used sequences as functions lots of times, and have them in the same project, but none of them required the passing variable to be explicitly declared outside of the function prototype.

What is different? I'm using latest v5.85.

Thanks in advance and as always, love the support from you guys.

(Are you sure you don't leave the odd bug/quirk in there just so we'll stay in touch?)

Link to comment
Share on other sites

If argc = 0, then you didn't pass any arguments, which means that RecipeNum is never declared, which is why you have to do the private RecipeNum = 99. If you do pass an argument, then argc will be > 0, RecipeNum will be declared as a private and assigned the value you pass in. Does that make sense? JavaScript works the same way really. Its not so much a DAQFactory thing, but a characteristic of loosely typed languages like DAQFactory and JavaScript.

In C++, VB and the like, everything is checked at compile time and has to line up. If a function declaration specifies a parameter, you have to provide one or the compiler will fail. Yes, you can make optional parameters, but they work differently, they aren't really optional, a default value is just provided in the function declaration, and so the parameter (local variable) is always declared. In DAQFactory and Javascript, optional parameters are just that, and if not provided they never exist. Make sense?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.