Topic Options
#65541 - 01/27/21 07:02 AM GV question
Samuel Kopstick Offline
Adagio Maestro

Registered: 06/15/07
Posts: 922
Loc: GTA & North America (Remote Su...
Client has Items in the format of XX/XXXXXXXXXXXXXX (2 segments, 2 & 14 characters).
The Items are entered in various lengths.
Some of the Items may appear with as few a 5 characters total (e.g. AP/W20), while others will be longer, up to using the full length (e.g. AP/12345678901234).

We have created a Gridview that reports details on the Items. We send this View as a spreadsheet to their Supplier.
So far, no problem.

Here is the issue:
The Supplier wants us to generate the spreadsheet so that the column with the Item number will always be 26 characters long (for whatever reason).

How do we do this?
_________________________
Samuel Kopstick
S Kopstick & Associates Inc
Toronto, ON

Top
#65542 - 01/27/21 08:00 AM Re: GV question [Re: Samuel Kopstick]
Bruce Gardner Online   content
Adagio Wizard

Registered: 06/15/04
Posts: 3617
Loc: Toronto ON, Canada
Hi Samuel:

In GridView you could try a Calculated Field like: MID(TRIM([Item number fieldname])&" ", 1, 26) where the spaces after the ampersand pad out the length to at least 26 characters (have to be at least 25 spaces, though it doesn't appear that way on in this post).

Most languages have a PAD() function but GridView doesn't so we have to make our own.
_________________________
Bruce Gardner
ARX Business Solutions Inc.

Top
#65543 - 01/27/21 09:00 AM Re: GV question [Re: Bruce Gardner]
Samuel Kopstick Offline
Adagio Maestro

Registered: 06/15/07
Posts: 922
Loc: GTA & North America (Remote Su...
Thanks Bruce.
This did not provide the solution we hoped for, It only added one more character to the field.

But you got me thinking again and after playing around, I came up with the formula. Here it is:
{Item #} & Repeat(" ", 26 - Length({Item #}))

The Repeat function allows us to tell GV to repeat a string a number of times.
As you may see in the formula, I was able to get GV to calculate how many characters each Item # is, using the Length function.
Finally, we ask GV to extend a bunch of additional spaces to pad the field to 26 characters.

It works!
_________________________
Samuel Kopstick
S Kopstick & Associates Inc
Toronto, ON

Top
#65559 - 01/28/21 02:12 PM Re: GV question [Re: Samuel Kopstick]
Retired_Guy Offline
Adagio Master

Registered: 03/16/99
Posts: 10504
Loc: Canada
When typing formulas on the Forum for people to read, I would suggest using the {code} style which indents and switches to a monospaced font so it's easy to see significant spaces. You need square brackets "[style name]" for a style to be recognized.

If you want all strings to be a specific length, then appending that number of spaces and taking the leftmost characters is probably the most efficient way of doing this:
Code:
LEFT({string expression}&"as many spaces as you need",n)
where "n" is the required length of the string.

This will evaluate slightly faster than calculating the number of spaces needed each time.

I think Sam missed Bruce's comment that the his formula (which uses "MID" rather than "LEFT" so needs two parameters) required 25 spaces to be specified. The reformatting of the reply for the Forum removes the duplicate spaces unless the {code} format is used.

Bruce's formula would display as:
Code:
MID(TRIM([Item number fieldname])&"                         ", 1, 26)
_________________________
Andrew Bates

Top
#65561 - 01/28/21 10:16 PM Re: GV question [Re: Retired_Guy]
Bruce Gardner Online   content
Adagio Wizard

Registered: 06/15/04
Posts: 3617
Loc: Toronto ON, Canada
Andrew:

Code:
So that's this works! Your interpretation of my post was correct. The string of blanks just didn't format correctly


Now that I've learned this, I'll have to remember because the [code] style-name doesn't appear to be one of the buttons.
_________________________
Bruce Gardner
ARX Business Solutions Inc.

Top


Moderator:  Christa_Meissner 
Who's Online
1 registered (Lauren Stief), 51 Guests and 0 Spiders online.
Key: Admin, Global Mod, Mod
Forum Stats
1865 Members
5 Forums
14484 Topics
70731 Posts

Max Online: 432 @ 01/20/25 10:17 PM
May
Su M Tu W Th F Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31