returning string from function
Posted by mcpeek on Aug 11, 2010; 12:33am
URL: http://imagej.273.s1.nabble.com/returning-string-from-function-tp3687299.html
Hi,
I am trying to return a string variable from a function to the main body of a macro. The string variable has the right value inside the function, but when it is passed back to the macro body, it has a value of 0.
I'm new to ImageJ, so I thought that maybe strings might be considered objects in some way (e.g., arrays of characters), and so needed to be passed by reference as with variables declared as arrays from the start. This didn't work either.
Any insight as to why this won't work, and what will make it work, would be greatly appreciated. A little test macro is below, using the get time test macro as a function.
Thanks,
Mark
*** Code to Follow ***
macro "test" {
timeString = "";
timeString = getTime();
showMessage(timeString);
}
function getTime() {
MonthNames = newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
DayNames = newArray("Sun", "Mon","Tue","Wed","Thu","Fri","Sat");
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
TimeString ="Date: "+DayNames[dayOfWeek]+" ";
if (dayOfMonth<10) {TimeString = TimeString+"0";}
TimeString = TimeString+dayOfMonth+"-"+MonthNames[month]+"-"+year+"\nTime: ";
if (hour<10) {TimeString = TimeString+"0";}
TimeString = TimeString+hour+":";
if (minute<10) {TimeString = TimeString+"0";}
TimeString = TimeString+minute+":";
if (second<10) {TimeString = TimeString+"0";}
TimeString = TimeString+second;
showMessage(TimeString);
return(TimeString);
}