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

Accepting data in form of column, converting to string

I'm trying to do the following:

 

Accept this input from user: 

A1234965
A1233339
A1234736
A123494Z
A1233114

 

Convert it to the string: "A1234965,A1233339,A1234736,A123494Z,A1233114"

 

With no limit on how long the inputted "column" is. I want the user to paste the "column" into a popup window that asks for it, then store that data as the string above. My real problem is finding a way to accept that input from the user ("text edit box" won't let a column-format be pasted). Then, of course, I don't know how to convert that input into the string format I need. Any help would be appreciated. Thanks!

3 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Accepting data in form of column, converting to string

Use the Concat Items() function

names default to here(1);

x={"aa","bb"};

y=concat items(x,",");
Jim

View solution in original post

jthi
Super User

Re: Accepting data in form of column, converting to string

You will have to split the data first using Words() before using Concat Items(). Depending where the data is being pasted from, sometimes you might have to perform some substitutions before using Words(). These can be done with Regex() using GLOBALREPLACE or Substitute()/Substitute Into().

 

It also might be good idea to remove duplicates (Associative Arrays can be used for this, if it doesn't matter that they will be ordered alphabetically).

-Jarmo

View solution in original post

julian
Community Manager Community Manager

Re: Accepting data in form of column, converting to string

Hi @aidanweb ,

It sounds like you're set on how to parse the entry, but that the display of the entry is giving you issues. It may seem like the text edit box is only taking in one line when in fact all the lines are pasting just fine, but the height of the box isn't allowing you to see them (if you arrow up and down in the edit box you'll see the other lines).

 

What I would do is pre-size the edit box when making the dialog to roughly the expected size of the paste. You can do that by adding something like:

b1<<SetNLines(10)<<set width(150);

julian_1-1689855037582.png

I hope this helps!

@julian 

 

Lots = "abc";

w = New Window("Lot(s) of Interest",
	Border Box(top(50), bottom(50), Left(50), Right(50),
		V List Box(
			H Center Box(Text Box("Lot(s) of Interest Input")),
			Spacer Box(size(1, 30)),
			H List Box(Text Box("Lots: "), b1 = Text Edit Box(Lots)),
			Spacer Box(size(1, 10)),
			H Center Box(
				Button Box("Save",
					Lots = b1 << get text;
					w << closeWindow; 
				)
			)
		)
	)
);
b1<<SetNLines(10)<<set width(150);

 

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: Accepting data in form of column, converting to string

Use the Concat Items() function

names default to here(1);

x={"aa","bb"};

y=concat items(x,",");
Jim
aidanweb
Level II

Re: Accepting data in form of column, converting to string

Thank you, I'll definitely be using the concat function. My big problem is taking in the user input. They'd be copying a column from a datatable and pasting it into an edit box. In my current code (seen below), it'll only take the first cell of the copied column... I'm assuming this is because I'm using a "Text Edit Box" and the Text data type - is there an edit box and data type that could take data formatted like this?:

 

A1234965
A1233339
A1234736
A123494Z
A1233114

 

 

Here's my current code:

 

Lots = "abc";

w = New Window("Lot(s) of Interest",
	Border Box(top(50), bottom(50), Left(50), Right(50),
		V List Box(
			H Center Box(Text Box("Lot(s) of Interest Input")),
			Spacer Box(size(1, 30)),
			H List Box(Text Box("Lots: "), b1 = Text Edit Box(Lots)),
			Spacer Box(size(1, 10)),
			H Center Box(
				Button Box("Save",
					Lots = b1 << get text;
					w << closeWindow; 
				)
			)
		)
	)
);
jthi
Super User

Re: Accepting data in form of column, converting to string

You will have to split the data first using Words() before using Concat Items(). Depending where the data is being pasted from, sometimes you might have to perform some substitutions before using Words(). These can be done with Regex() using GLOBALREPLACE or Substitute()/Substitute Into().

 

It also might be good idea to remove duplicates (Associative Arrays can be used for this, if it doesn't matter that they will be ordered alphabetically).

-Jarmo
aidanweb
Level II

Re: Accepting data in form of column, converting to string

Thank you, this helps tons. I'm still having an issue converting the input into a list, formatted like so: {"aa", "bb", "cc"}. I would've thought the words function would work right away, as the input is just a long string.... but I'm probably doing something wrong. I attached a screenshot of my log. 

 

aidanweb_0-1689866223428.png

 

Jeff_Perkinson
Community Manager Community Manager

Re: Accepting data in form of column, converting to string

You missed including the appropriate delimiter in the Words() function. In your case you want an end of line character (or characters) as the delimiter. See the table of Escape Sequences for Quoted Strings in the JSL syntax rules.

 

Try this:

Names Default To Here( 1 );
Lots = "abc";
w = New Window( "Lot (s) of Interest",
	Border Box( top( 50 ), bottom( 50 ), Left( 50 ), Right( 50 ),
		V List Box(
			H Center Box( Text Box( "Lot (s) of Interest Input" ) ),
			Spacer Box( size( 1, 30 ) ),
			H List Box( Text Box( ("Lots: ") ), b1 = Text Edit Box( Lots, <<SetNLines( 10 ), <<set width( 150 ) ) ),
			Spacer Box( size( 1, 10 ) ),
			H Center Box(
				Button Box( "Save",
					Lots = b1 << get text;
					W << close window;
//include the delimiters for carriage and new line in the Words() function newlots = Words( Lots, "\!r\!n" ); Show( Lots ); Show( newlots ); ) ) ) ) );

 

 

-Jeff
julian
Community Manager Community Manager

Re: Accepting data in form of column, converting to string

Hi @aidanweb ,

It sounds like you're set on how to parse the entry, but that the display of the entry is giving you issues. It may seem like the text edit box is only taking in one line when in fact all the lines are pasting just fine, but the height of the box isn't allowing you to see them (if you arrow up and down in the edit box you'll see the other lines).

 

What I would do is pre-size the edit box when making the dialog to roughly the expected size of the paste. You can do that by adding something like:

b1<<SetNLines(10)<<set width(150);

julian_1-1689855037582.png

I hope this helps!

@julian 

 

Lots = "abc";

w = New Window("Lot(s) of Interest",
	Border Box(top(50), bottom(50), Left(50), Right(50),
		V List Box(
			H Center Box(Text Box("Lot(s) of Interest Input")),
			Spacer Box(size(1, 30)),
			H List Box(Text Box("Lots: "), b1 = Text Edit Box(Lots)),
			Spacer Box(size(1, 10)),
			H Center Box(
				Button Box("Save",
					Lots = b1 << get text;
					w << closeWindow; 
				)
			)
		)
	)
);
b1<<SetNLines(10)<<set width(150);

 

aidanweb
Level II

Re: Accepting data in form of column, converting to string

 

 

 

jthi
Super User

Re: Accepting data in form of column, converting to string

Like I said earlier, use Words() to split it into a list. Then use Concat Items() to combine that list back to a string. It might be enough to use \!N as separator with Words() but sometimes it might not work correctly

Names Default To Here(1);

str = "abc
def";

lst = Words(str, "\!N");

str2 = "'" || Concat Items(lst, "','") || "'";

show(str, lst, str2);

 

Edit:

As this can be fairly common task to do with JSL below is complete example. This example does contain some a bit more advanced techniques which can be used when building user-interfaces with JSL, so it is a good idea to start with the example @julian provided first.

View more...
Names Default To Here(1);

lotquery = ""; // initialize as empty

initial_input = "A1234965
A1233339
A1234736
A123494Z
A1233114
A1233114";

nw = New Window("Lot(s) of Interest", Show Toolbars(0), Show Menu(0),// << modal,
	Border Box(top(10), bottom(5), Left(20), Right(20),
		V List Box(align("center"),
			Text Box("Input lots of interest:"),
			Text Edit Box(initial_input, << Set NLines(10), << set width(250)), // << Set Text Changed or << Set Function can be used for cleanup during input
			Spacer Box(size(300, 10)), // Use wide spacer box to easily force window width
			Panel Box("Actions",
				Lineup Box(N Col(2),
					Button Box("OK", 
						<< Set Function(function({this},
							Local({input_values, input_list},
								input_values = (this << top parent)[Text Edit Box(1)] << get text;
								If(IsMissing(input_values), // very lazy check
									Throw("No lots provided!");
								);
								input_list = Associative Array(Words(input_values, "\!N")) << get keys; // aa to remove duplicates
								lotquery = "'" || Concat Items(input_list, "', '") || "'";
							);
							write("Input lots: " || lotquery);
							(this << top parent) << Close Window;
						));
					),
					Button Box("Close", 
						<< Set Function(function({this}, 
							(this << top parent) << Close Window;
						))
					)
				)
			)
		)
	),
	<< Set Window Icon("WebBrowserImportAsData")
);

/* // if modal is used
If(nw["Button"] != 1,
	Throw("Cancel pressed");
);

If(IsMissing(lotquery),
	Throw("No lots provided!");
);
*/
Write();

jthi_0-1689866153494.png
-Jarmo