LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ViConstString convert

I am working with a niSwitch which uses variable type ViConsString. I know I can set the variable to say "com1". But what I want to be able to do is loop through all 8 com lines in a for loop, incrementing the number in the string on each pass. I could do this with unsigned char using strcat, Fmt and strcpy, but unsure how to do it with a ViConstString. An example of how I might do this with a unsigned char is as follows:

unsigned char chan[5] = {0};

for(i=0;i<8;i++)
{
strcpy(ucTemp,"com");
Fmt(chan,"%d",i);
strcat(ucTemp,chan);
}

ucTemp = "com0", "com1",....
0 Kudos
Message 1 of 3
(4,088 Views)
Hello Wadet,

I tried to track down a shipping example that use the ViConstString data type to test out my suggestion but I was unable to do so, but have you tried casting the ViConstString variable to a character pointer. The ViConstString data type is defined in the visatype.h file. There, it is defined as a pointer a character. If this is the case, it seems like you would be able to do something like:

1. Cast ViConstString variable to (char *)variable.
2. Perform string manipulation as suggested in your post.
3. Cast back to ViConstString.

Please let me know any compile errors your get, or if you have sample code to test this out.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 3
(4,067 Views)
Thanks for the reply. I ended up finding a way around it. I did try typecasting, but there might of been something else I was having trouble with at the time.

Thank you for the suggestion
0 Kudos
Message 3 of 3
(4,059 Views)