Jump to content

Is it possible declare function Input array as variable length


Annatooli

Recommended Posts

I have two identical functions, except "Function In" has different array lengths.

Inside function I can easily determine  array length with "Array Size", but understandably "Function In"  doesn't  accept different array lengths.

Is it possible declare "Function In" so it will accept different length of arrays ??

I figured if I declare short arrays they will accepts calls with longer arrays. Question, Is entire array accessible from  function or only smaller subset ?

Link to comment
Share on other sites

  • MVP 2023

The input tag parameters are pretty much set in stone when you define a function, so I'm going to guess you don't get to make the array length dynamic.  Maybe one of the Creators can chime in and verify.

Is there a reason why you can't define the larger array as the input parameter and then not fill it all the way?  It would add extra code, but you could initialize the array to zero before you loaded it and passed it and then figure out where in the array the zeros start to determine size.

If the function is not overly complex I'd just make two that fits your needs.  In PLC land we often have to make due with the tools we're given.

Joe T.

Link to comment
Share on other sites

The array length is passed to the function as  a parameter (if I remember correctly), but you can't use it. However, if you use a C Function then you can see it in the function declaration, and also write code that use pointers in order to get the relevant data from the desired index.

This off course require knowing C, and you need to know what you are doing in order to avoid CPU Error.

Link to comment
Share on other sites

Thanks for reply.

I will keep both functions for now, but If I need more of those functions I will make unified array lengths, and add parameter with length.

I did look into C code but I cant figure out what to do with "bit" variable type. It is "unsigned char" in C, but not in examples nor in  documentation is mentioned  what I should put into those variables for returning  true and false.

 

 

Link to comment
Share on other sites

So , like this ??

// User code starts below this comment

// User code ends above this comment

static void Boolean(unsigned char A, volatile unsigned char* C)
{
	// User code starts below this comment
		if(!A){
			*C = 0; // false
		}else{
			*C = 1; // true
		}
	// User code ends above this comment
}

// User code starts below this comment

It does compile, just there is "char" in type name. So I assumed it has to be some sort character.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...