LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I resize an array of strings?

I'm having a problem of not being able to use the CIN functions and therefore can't use the convenient resizing methods. I have tried to use NumericArrayResize to resize an array of strings, but it's not working correctly. Here's what I've tried most recently. I have tried many variations, so if you want to modify what I have posted, or just provide new code, please feel free.


typedef struct {
int32 dimSize;
LStrHandle elt[1];
} LStrHandleArray;

typedef LStrHandleArray **LStrHandleArrayHandle;

void someMethod(LStrHandleArrayHandle arrayOut) {
// attempting to write the string "asdf" in the first element in the array. (1D array)

int newSize = 1;

MgErr e = NumericArrayResize(uL, 1L, (UHandle*)&arr
ayOut, newSize);

(*arrayOut)->dimSize = newSize;
LStrHandle hdl = *(*arrayOut)->elt;

long str_size = strlen("asdf");

MgErr err = NumericArrayResize(uB, 1L,(UHandle *)&hdl, str_size);

LStrLen(*hdl) = str_size;

MoveBlock("asdf", LStrBuf(*hdl), str_size);
}




The code above doesn't result in crashing labview at any time. The string "asdf" is not copied though. And, after being able to copy one string I would like to extend this to many elements in a 1D array of strings.

Thanks!
Naveen
0 Kudos
Message 1 of 2
(2,790 Views)
LabVIEW stores string arrays as an array of handles to those strings. To resize an array of strings you need to declare a new string in LabVIEW's data space, resize the handle array, and add a handle to your new string. Here is an example program which does this.

-Aaron Marks
National Instruments
0 Kudos
Message 2 of 2
(2,790 Views)