Concatenating Rules


cadcoke5

Recommended Posts

I have following sequence that has an error on the last line,

C1097 String operator found when number expected.: test Line 11 - Uncaught error in sequence test

Global ExtractedHrs = 0
Global ExtractedMin = 0
Global string HrsMin
Global seconds = 3690.599

ExtractedHrs = floor(seconds/3600)
ExtractedMin = floor((seconds - floor(seconds/3600)*3600)*100)/100  // isolate remainder seconds and convert to two decimal place

HrsMin = ExtractedHrs + "hrs and " + ExtractedMin

I have tried several variations.  The code below generates the same error;

? ExtractedHrs + "hrs and " + ExtractedMin

What am I not getting about strings?

 

-Joe

Link to comment
Share on other sites

DAQFactory will automatically convert numbers to strings when concatenating strings but it won't do the reverse. This is because + has two meanings. If the thing to the left is a number it means addition. If its a string it means concatenation. Since extractedhrs is a number it thinks you are adding and you can't add strings.

Two ways to do what you want:

1- use doubletostr() or format() to convert the first number to a string

2- put "" + in front so the first thing the expression sees is a string

Note you don't need to worry about the last number because there is a string to its left.

Link to comment
Share on other sites

Archived

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