cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Jaz
Jaz
Level IV

RE: Name Unresolved & Deleted Object Reference

Hi,

 

I'm basically trying to access a variable that's been created within a function. I'm trying to print that variable outside of the function but keep getting name unresolved / deleted reference 'Glue' errors. I basically have a function for a button which creates a new window and stores the value of lf inside that function and window creation. I want to be able to print the value of lf but I'm not sure how. Any suggestions would be appreciated. Another question is that when I print lf inside of the OKscript1 function, it isn't printed to the log. Is that because OKscript1 isn't a function but an Expr? Also, when I run the program the first time after selecting a file, I get a name unresolved error. But when I run it again and select a different file and view the log then the previous file I had selected before exiting appears in the log. Any ideas as to why? I think its probably either a really simple thing I've overlooked or something to do with my scoping?

mainWindow = New Window("Instruction Tagger",
	ob = Outline Box("Instruction Tagger",
		Border Box(Left(3), top(2),
			V List Box(
				H List Box( 
					Panel Box("Please choose one of the following options:", <<Markup(1),  
						Button Box("Tag a Single File", singleFileButton1("Tag Instructions to Data") ),
						Button Box( "Tag Multiple Files", singleFileButton1("Tag Instructions to Data") ), 
						Text Box("Note: a button to tag the data will appear automatically after you have selected the measurement & PFD files. ")
					)
				)
			)
		)
	)
);  



singleFileButton1 = Function({x}, 
mainWindow << Close Window; 
choosingFilesWindow = New Window(x,   
	ob = Outline Box("Select Your Files: ", 
		Border Box (Left(3), top(2)), 
			vDisplay = V List Box( 
				H List Box(
					Panel Box("Please select one of the options below to choose your measurement & PFD file: ", <<Markup(1), 
						Button Box("Select Measurement File", selectMeasurementFileButton("Select Measurement File")), 
						Button Box("Select PFD File", selectPFDFileButton("Select PFD File")), 
						Lineup Box (N Col(2), Spacing(3)), 
						Panel Box("Files Added",
						CB = Check Box({"Measurement file added", "PFD file added"},<<Set(1,0),<<Set(2,0),<<Enable Item(1,0),<<Enable Item(2,0))),
						Text Box("Note: The relevant check-boxes above will be ticked once the file has been added.",<< Set Wrap( 500 )),
						hidden = Button Box("Commence tagging")))))));
selectMeasurementFileButton = Function({y}, 
title = y;
lbWidth = 220;
nc=12;
selectedDir = Pick Directory();
fileList = Files In Directory( selectedDir );
fileSelected = {};

// *********************************************************************************
// Build custom dialog in a window
// *********************************************************************************
win1 = New Window( "Select Files",
	Border Box( Left( 3 ), top( 2 ),
		V List Box(
			H List Box(
				Panel Box( "Available Files ", ListData = List Box( fileList, width( lbWidth ), nLines( Min( nc, 12 ) ) ) ),
				Panel Box( "Selected File ",
					Lineup Box( N Col( 2 ), Spacing( 3 ),
						Button Box( "File To Tag", ListF << Append( ListData << GetSelected ) ),
						ListF = List Box( fileSelected, width( lbWidth ), nLines( 5 ), Numeric )
					)
				),
				Panel Box( "Action",
					Lineup Box( N Col( 1 ),
						okButton = Button Box( "OK", OKScript1),
						Button Box( "Cancel",
							//win1 << CloseWindow;
							Throw();
						),
						Text Box( " " ),
						Button Box( "Remove", RemoveScript1)
					)
				)
			)				// End of HListBox
		)					// End of VListBox
	)						// End of BorderBox
);							// End of NewWindow



); // End of button function 

// *********************************************************************************
// Do this when the user hits OK
// ********************************************************************************* 
OKScript1 = Expr( 
	//win1 << CloseWindow; 
	//Names Default To Here(1);
	lf = ListF << Get Items;  
	if (lf != {} & N Items(lf) == 1 , CB << Set(1,1); Throw("Success: Measurement file has been added."),CB << Set(1, 0)); 
	if(Try(N Items(lf) > 1), Throw ("Error: Please only select one measurement file. Alternitavely, go back and select 'Tag Multiple Files'. "));
	if(Try(N Items(lf) < 1), Throw ("Error: Please select one measurement file.Alternitavely, go back and select 'Tag Multiple Files'.")); 
); 

print(lf); 

print(lf); 

 

1 ACCEPTED SOLUTION

Accepted Solutions
cwillden
Super User (Alumni)

RE: Name Unresolved & Deleted Object Reference

Hi @Jaz,


I patched up the indentation on this script because it was hard to follow.  I also removed the <<Markup(1) stuff because you didn't have any html tags in your text anyway and it was causing warning messages. 

 

A couple issues here:  When you run the script, it's going to run those "print(lf)" lines you had at the bottom before the user even does anything with the dialogs.  "lf" doesn't even exist yet when you're asking JMP to print it.  You have to put it within the OKScript1 expression so that line of code is run only when the user presses OK.

 

You also cannot close the window before you get the items from ListF because ListF won't exist anymore.  You did have that line of code commented out, so I'm not sure if that was causing your "deleted object reference" error or not.

 

The script below seems to work.  I get no errors and print(lf) is working.  It showed the files I selected in a list in the log.

mainWindow = New Window("Instruction Tagger",
	ob = Outline Box("Instruction Tagger",
		Border Box(Left(3), top(2),
			V List Box(
				H List Box( 
					Panel Box("Please choose one of the following options:",  
						Button Box("Tag a Single File", singleFileButton1("Tag Instructions to Data") ),
						Button Box( "Tag Multiple Files", singleFileButton1("Tag Instructions to Data") ), 
						Text Box("Note: a button to tag the data will appear automatically after you have selected the measurement & PFD files. ")
					)
				)
			)
		)
	)
);  



singleFileButton1 = Function({x}, 
	mainWindow << Close Window; 
	choosingFilesWindow = New Window(x,   
		ob = Outline Box("Select Your Files: ", 
			Border Box (Left(3), top(2)), 
			vDisplay = V List Box( 
				H List Box(
					Panel Box("Please select one of the options below to choose your measurement & PFD file: ",
						Button Box("Select Measurement File", selectMeasurementFileButton("Select Measurement File")), 
						Button Box("Select PFD File", selectPFDFileButton("Select PFD File")), 
						Lineup Box (N Col(2), Spacing(3)), 
						Panel Box("Files Added",
						CB = Check Box({"Measurement file added", "PFD file added"},<<Set(1,0),<<Set(2,0),<<Enable Item(1,0),<<Enable Item(2,0))),
						Text Box("Note: The relevant check-boxes above will be ticked once the file has been added.",<< Set Wrap( 500 )),
						hidden = Button Box("Commence tagging")
					)
				)
			)
		)
	)
);

selectMeasurementFileButton = Function({y}, 
	title = y;
	lbWidth = 220;
	nc=12;
	selectedDir = Pick Directory();
	fileList = Files In Directory( selectedDir );
	fileSelected = {};

	// *********************************************************************************
	// Build custom dialog in a window
	// *********************************************************************************
	win1 = New Window( "Select Files",
		Border Box( Left( 3 ), top( 2 ),
			V List Box(
				H List Box(
					Panel Box( "Available Files ", ListData = List Box( fileList, width( lbWidth ), nLines( Min( nc, 12 ) ) ) ),
					Panel Box( "Selected File ",
						Lineup Box( N Col( 2 ), Spacing( 3 ),
							Button Box( "File To Tag", ListF << Append( ListData << GetSelected ) ),
							ListF = List Box( fileSelected, width( lbWidth ), nLines( 5 ), Numeric )
						)
					),
					Panel Box( "Action",
						Lineup Box( N Col( 1 ),
							okButton = Button Box( "OK", OKScript1),
							Button Box( "Cancel",
								//win1 << CloseWindow;
								Throw();
							),
							Text Box( " " ),
							Button Box( "Remove", RemoveScript1)
						)
					)
				)				// End of HListBox
			)					// End of VListBox
		)						// End of BorderBox
	);							// End of NewWindow
); // End of button function 

// *********************************************************************************
// Do this when the user hits OK
// ********************************************************************************* 
OKScript1 = Expr( 
	lf = ListF << Get Items; 
	print(lf);
	win1 << Close Window; 
	if (lf != {} & N Items(lf) == 1 , CB << Set(1,1); Throw("Success: Measurement file has been added."),CB << Set(1, 0)); 
	if(Try(N Items(lf) > 1), Throw ("Error: Please only select one measurement file. Alternitavely, go back and select 'Tag Multiple Files'. "));
	if(Try(N Items(lf) < 1), Throw ("Error: Please select one measurement file.Alternitavely, go back and select 'Tag Multiple Files'.")); 
);

I'd recommend changing the "Success" if statement at the end.  I don't believe that CB << Set(1,0) is going to be evaluated because you've already used Throw() to stop further processing.  Consider replacing Throw() with Caption() in that box.  That also makes it so the "success" message doesn't look like an error as it does with Throw().

-- Cameron Willden

View solution in original post

2 REPLIES 2
cwillden
Super User (Alumni)

RE: Name Unresolved & Deleted Object Reference

Hi @Jaz,


I patched up the indentation on this script because it was hard to follow.  I also removed the <<Markup(1) stuff because you didn't have any html tags in your text anyway and it was causing warning messages. 

 

A couple issues here:  When you run the script, it's going to run those "print(lf)" lines you had at the bottom before the user even does anything with the dialogs.  "lf" doesn't even exist yet when you're asking JMP to print it.  You have to put it within the OKScript1 expression so that line of code is run only when the user presses OK.

 

You also cannot close the window before you get the items from ListF because ListF won't exist anymore.  You did have that line of code commented out, so I'm not sure if that was causing your "deleted object reference" error or not.

 

The script below seems to work.  I get no errors and print(lf) is working.  It showed the files I selected in a list in the log.

mainWindow = New Window("Instruction Tagger",
	ob = Outline Box("Instruction Tagger",
		Border Box(Left(3), top(2),
			V List Box(
				H List Box( 
					Panel Box("Please choose one of the following options:",  
						Button Box("Tag a Single File", singleFileButton1("Tag Instructions to Data") ),
						Button Box( "Tag Multiple Files", singleFileButton1("Tag Instructions to Data") ), 
						Text Box("Note: a button to tag the data will appear automatically after you have selected the measurement & PFD files. ")
					)
				)
			)
		)
	)
);  



singleFileButton1 = Function({x}, 
	mainWindow << Close Window; 
	choosingFilesWindow = New Window(x,   
		ob = Outline Box("Select Your Files: ", 
			Border Box (Left(3), top(2)), 
			vDisplay = V List Box( 
				H List Box(
					Panel Box("Please select one of the options below to choose your measurement & PFD file: ",
						Button Box("Select Measurement File", selectMeasurementFileButton("Select Measurement File")), 
						Button Box("Select PFD File", selectPFDFileButton("Select PFD File")), 
						Lineup Box (N Col(2), Spacing(3)), 
						Panel Box("Files Added",
						CB = Check Box({"Measurement file added", "PFD file added"},<<Set(1,0),<<Set(2,0),<<Enable Item(1,0),<<Enable Item(2,0))),
						Text Box("Note: The relevant check-boxes above will be ticked once the file has been added.",<< Set Wrap( 500 )),
						hidden = Button Box("Commence tagging")
					)
				)
			)
		)
	)
);

selectMeasurementFileButton = Function({y}, 
	title = y;
	lbWidth = 220;
	nc=12;
	selectedDir = Pick Directory();
	fileList = Files In Directory( selectedDir );
	fileSelected = {};

	// *********************************************************************************
	// Build custom dialog in a window
	// *********************************************************************************
	win1 = New Window( "Select Files",
		Border Box( Left( 3 ), top( 2 ),
			V List Box(
				H List Box(
					Panel Box( "Available Files ", ListData = List Box( fileList, width( lbWidth ), nLines( Min( nc, 12 ) ) ) ),
					Panel Box( "Selected File ",
						Lineup Box( N Col( 2 ), Spacing( 3 ),
							Button Box( "File To Tag", ListF << Append( ListData << GetSelected ) ),
							ListF = List Box( fileSelected, width( lbWidth ), nLines( 5 ), Numeric )
						)
					),
					Panel Box( "Action",
						Lineup Box( N Col( 1 ),
							okButton = Button Box( "OK", OKScript1),
							Button Box( "Cancel",
								//win1 << CloseWindow;
								Throw();
							),
							Text Box( " " ),
							Button Box( "Remove", RemoveScript1)
						)
					)
				)				// End of HListBox
			)					// End of VListBox
		)						// End of BorderBox
	);							// End of NewWindow
); // End of button function 

// *********************************************************************************
// Do this when the user hits OK
// ********************************************************************************* 
OKScript1 = Expr( 
	lf = ListF << Get Items; 
	print(lf);
	win1 << Close Window; 
	if (lf != {} & N Items(lf) == 1 , CB << Set(1,1); Throw("Success: Measurement file has been added."),CB << Set(1, 0)); 
	if(Try(N Items(lf) > 1), Throw ("Error: Please only select one measurement file. Alternitavely, go back and select 'Tag Multiple Files'. "));
	if(Try(N Items(lf) < 1), Throw ("Error: Please select one measurement file.Alternitavely, go back and select 'Tag Multiple Files'.")); 
);

I'd recommend changing the "Success" if statement at the end.  I don't believe that CB << Set(1,0) is going to be evaluated because you've already used Throw() to stop further processing.  Consider replacing Throw() with Caption() in that box.  That also makes it so the "success" message doesn't look like an error as it does with Throw().

-- Cameron Willden
Jaz
Jaz
Level IV

RE: Name Unresolved & Deleted Object Reference

Hi @cwillden,

 

Thanks so much for the help. I was supposed to have a tag to make my text bold which was why I used Markup but I realised I took them out. I changed the throws and text boxes to captions just for consistency. Thanks again for the explanation.