Page 1 of 1

Taking photos on the Navbar

Posted: July 27th, 2018, 3:12 pm
by Don
Hi, I created two navbar buttons that would take a photo and display a photo for the current case. I would like the photo to be named with the ID items. However, when I take the photo, the photo name is blank even if I take it after entering the ID items. My code is below.

Code: Select all

PROC GLOBAL
string 	photoDir,		//Stores the location of the photos folder
		photoFileName 	//filename of photo
		;
		
//Function to take a photo using the device's camera. It saves to a filename matching the ID items
function takePhoto()
	if direxist(photoDir) then
		execsystem(maketext("camera:%s",photoFileName));
	else
		dircreate(photoDir);
		execsystem(maketext("camera:%s",photoFileName));
	endif;
end;

//Function to view photo of current case
function viewPhoto()
	if direxist(photoDir) then
		execsystem(maketext("view:%s", photoFileName));
	else
		dircreate(photoDir);
		execsystem(maketext("view:%s", photoFileName));
	endif;
end;

PROC LABOURFORCE_FF
preproc
	photoFileName = pathname(CSEntry) + maketext("Menu/Photos/%03d-%03d-%d-%03d.jpg", visualvalue(RNDNO),visualvalue(EDNO),visualvalue(STRATUM),visualvalue(HHNO));  //DEBUG: Not saving file with Rndno, edno, and stratum
	photoDir = pathname(CSEntry) + "Menu/Photos";
	
	userbar(clear);
	userbar(add button, "Get Location", getgps());		//adds a "Get location" button to get coordinates
	userbar(add button, "Take a photo for the current case", takePhoto());		//adds a button to take a photo of current case. 
	userbar(add button, "View photo of current case", viewPhoto());		//adds a button to view photo of current case
	userbar(show);
When I press the button, I get a photo with the name " - - - .jpg". As I said before, It happens even after entering RNDNO, EDNO, STRATUM and HHNO. Is there a reason for this? I've tried it with and without visualvalue on the variables.

Re: Taking photos on the Navbar

Posted: July 27th, 2018, 4:23 pm
by josh
You are setting the value of photoFileName in LABOURFORCE_FF preproc which is the preproc of the application. It gets called once when the application first starts well before entering the values of the id-items. At the time that LABOURFORCE_FF preproc is run the id-items do not yet have any value.

Try moving the line that sets photoFileName to the beginning of the takePhoto() function.

Re: Taking photos on the Navbar

Posted: August 3rd, 2018, 11:52 am
by Don
It works thanks!