Subscribe Bookmark RSS Feed

Assign table reference to selected item from list box

RyMcQeN

Occasional Contributor

Joined:

Nov 16, 2016

Hello,

 

I am attempting to script a dialog window that prompts the user to select 2 data tables from a pair of list boxes that display all currently open table names.  The dialog window, list box, and selection process all work as intended however once I have the 2 selected table names as variables I hit a road block when trying to associate them to data table references.  The data table references are needed to perform work on the selected tables later in the code. 

 

Issues arrise at the last two lines with the following error for dt1.

Argument must contain data table reference in access or evaluation of 'Current Data Table' , Current Data Table/*###*/(SourceData)

 

I realize that SourceData and TargetData are list objects with only 1 item each so I tried converting to string before associating as a data table name but that didn't work. 

 

Any help is greatly appreciated. Please refer to script section below.

 

openTables = {};

For (t=1, t<=NTable(), t++, InsertInto(openTables, DataTable(t) << GetName));

SelectDataWindow = New Window( "Select data tables", <<Modal,

SourcePanel = Panel Box("Source Data Table",

SourceListBox = List Box(openTables, Max Selected(1))),

TargetPanel = Panel Box("Target Data Table",

TargetListBox = List Box(openTables, Max Selected(1))),

Line Up Box(NCol(2), Button Box("Ok",

SourceData = SourceListBox << GetSelected;

TargetData = TargetListBox << GetSelected),

Button Box("Cancel", Stop()))

);

dt1 = CurrentDataTable(SourceData);

dt2 = CurrentDataTable(TargetData);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
David_Burnham

Super User

Joined:

Jul 13, 2011

Solution

First you want to use the function Data Table and not Current Data Table in the last two lines.

The argument to the Data Table needs to be the string name. If you show the contents of SourceData and TargetData you will see that the are lists. This is because in general listboxes allow a user to select multiple items.  So even though you are restricting the number of selected items to one the selection is still returned as a list.

You can replace the last two lines with this:

dt1 = Data Table( SourceData[1] );
dt2 = Data Table( TargetData[1] );

So now the first item of the lists is being used.

This of course presumes that the user has selected at least one item from each list. You can add validation to a modal window. After the line containing the Modal message add:

	<<OnValidate(
		If ( NItems(SourceData)>0  &  NItems(TargetData)>0,
			isValid = 1
		,
			isValid = 0;
			Beep()
		);
		isValid
	),

 Obviously you could extend this validation (e.g. to verify that the source and destination names were not identical ).

-Dave
2 REPLIES
David_Burnham

Super User

Joined:

Jul 13, 2011

Solution

First you want to use the function Data Table and not Current Data Table in the last two lines.

The argument to the Data Table needs to be the string name. If you show the contents of SourceData and TargetData you will see that the are lists. This is because in general listboxes allow a user to select multiple items.  So even though you are restricting the number of selected items to one the selection is still returned as a list.

You can replace the last two lines with this:

dt1 = Data Table( SourceData[1] );
dt2 = Data Table( TargetData[1] );

So now the first item of the lists is being used.

This of course presumes that the user has selected at least one item from each list. You can add validation to a modal window. After the line containing the Modal message add:

	<<OnValidate(
		If ( NItems(SourceData)>0  &  NItems(TargetData)>0,
			isValid = 1
		,
			isValid = 0;
			Beep()
		);
		isValid
	),

 Obviously you could extend this validation (e.g. to verify that the source and destination names were not identical ).

-Dave
RyMcQeN

Occasional Contributor

Joined:

Nov 16, 2016

This worked perfectly.  Thank you Dave!