Jump to content

Arraysize from reference


Bernd F

Recommended Posts

Hy to @ll,

i have the problem that i want to get the arraysize of a array i don't know the type of,

because i only get the reference of a "TD1Hdl" (C-Type).

So i cannot typecast the Array and use the "Array-size" block.

I want to grap the reference of one by one element and put this reference to an other VI.

alternative?

I could pass a array of references, too. One reference per element.

It would be more easy, but i didn't found something like "references to array elements[]".

Thanks for your help.

Bernd

PS.: I just used the Array of string, to create a ref to an array. I don't know the type of it.

post-6641-126479225955_thumb.jpg

Link to comment

This question sounds like you are on the path I was when I wrote this Nugget on the Dark-side (NI).

http://forums.ni.com/ni/board/message?board.id=170&thread.id=267659&view=by_date_ascending&page=1

In that Nugget I shared the code to see how I did it (cludge!). I had to resort to flattning the array to a variant and get the size then poke at the control until I made it bigger, then I knew what the size was in one dimension.. lather rinse repeat for the next dimention.

So the Correct answr (I believe) is you can not know without knowing the data type in the array, but the above Nugget does show "It can be done".

One of the reasons i posted that Nugget was to try and find a better way by posting that redicuous approach in the hopes someone would show me the "right way". I suspect there is no "right way".

Ben

Link to comment

i have the problem that i want to get the arraysize of a array i don't know the type of,

because i only get the reference of a "TD1Hdl" (C-Type).

So i cannot typecast the Array and use the "Array-size" block.

Hi Bernd,

You can get the Array Size even if I don't know the array type by using the OpenG's "Array Size(s)" that you can find in the Variant palette.

I want to grap the reference of one by one element and put this reference to an other VI.

I don't think you can do that. You can get the reference to the array element (default value), but it's not the Elements References[] you're looking for.

By looking at the class name of that default element reference, you can know what's the array datatype (or you can use OpenG's VIs again).

post-10515-12647978549_thumb.png

While Ben's method (Nugget) works great with controls, it doesn't scale well with an array of unknown dimensions and sizes. Actually, sizes are not a problem... but dimensions are. If you restrict yourself to a 1D array (or a 2D array), then you can convert it but you'll have to work with Variant data, not references to individual elements.

My advice would be to work with a variants in this case. It's heavier than carrying around the references, but overall it might be better to conserve dataflow in your program.

Link to comment
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...

Important Information

By using this site, you agree to our Terms of Use.