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