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);