cadcoke5 Posted March 20, 2014 Share Posted March 20, 2014 I am having difficulty creating a function. I actually have a few questions, let me start with just showing what I have. When I attempt to run my calling script, I get the error c1000 "Channel or function not found." I tried running the function, in case it had to be run first before DAQFactory recognized it, but that made no difference. I should point out that the value I want returned is a string. The function itself; function Seconds_to_HrMin(Arg0) Local ExtractedHrs = 0 Local ExtractedMin = 0 ExtractedHrs = floor(Arg0/3600) ExtractedMin = floor((Arg0 - floor(Arg0/3600)*3600)*100)/100 // isolate remainder seconds and convert to two decimal place Return ("" + ExtractedHrs + "hrs and " + ExtractedMin + " Sec") Then, the script that calls it is; Local string temp temp = Seconds_to_HrMin(3605) //note that 3600 seconds = 1 hr ? temp Thanks for the clarification on creating functions. -Joe Link to comment Share on other sites More sharing options...
AzeoTech Posted March 20, 2014 Share Posted March 20, 2014 Without the line number of the error, which it should have given you, I can't say for sure, but I can tell one thing: don't use "local" for private variables. "local" is only for declaring member variables in classes. To declare a private variable used only in the function, use "private": private extractedHrs = 0 That is most likely the problem. Also, FYI, there is a function called FormatDateTime() which will do what you want without all the fancy math. Link to comment Share on other sites More sharing options...
cadcoke5 Posted March 21, 2014 Author Share Posted March 21, 2014 Yes, I incorrectly used the word local to declare the variable, when I should have used private. This is something I had been confused about for a while. I see now that local variables are used for a different purpose. I did see the FormatDateTime() when I was looking for a way to do this, but it only seemed viable to extract the information for time in seconds from 1970. Also, it kept crashing DAQFactory, so I abandoned my effort to understand it. With your mention of it I dived back into it. I see now that it will work perfectly for my code. The crashes were triggered when putting a lower case s, which should have been uppercase. But, at least I learned more about functions! -Joe Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.