Solved

Padding a field with a space

Posted on 2009-03-29
2
3,085 Views
Last Modified: 2012-05-06
Hi All,

This should be an easy one.

I have a field that is two (2) characters in length. Sometimes the field will only have 1 character in it and most times it will be two,

I'm trying to add a space (" ") at the end of the data output so that it looks as follows:

Record #1 field has "AB" output 'AB'
Record #2 field has "A" output 'A ' (space after the A)

I think it something to do with the 'space' syntax and I can get it to work but it is adding it left of the field not right (i,e  ' A'


trimleft({HISMAST.CUSTOMER_ALPHA})+ right (space (2) + {HISMAST.STOCK_CATEGORY},2)+{HISMAST.STOCK_CODE}
 
// Customer_Alpha ="Arro"
// Stock_Category =W " - there is a space after the W field length 2
// Stock Code = "Multi"

Open in new window

0
Comment
Question by:logonlarry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:logonlarry
ID: 24015491
Hi All,

I have found the solution on Web.
 
You have to create a custom function and insert the following :

Function (stringvar InString, numbervar StrLength)
// PadExact - make a string field an exact length, (FoxPro PADR)
// Input: InString, the string to be trimmed or padded
// StrLength, the desired length
// Example: PadExact(City,10)+State
// Antioch TN
// Nashville TN
left(trim(InString)+ space(StrLength),StrLength) ;

Then I simply went

trimleft({HISMAST.CUSTOMER_ALPHA})+ PadExact({HISMAST.STOCK_CATEGORY},2)+{HISMAST.STOCK_CODE}

and Bingo all is good

Hope this helps others
0
 
LVL 35

Accepted Solution

by:
James0628 earned 500 total points
ID: 24017470
The function is a bit much.  All you needed to do was change how you added the space.

right (space (2) + {HISMAST.STOCK_CATEGORY},2)

 should be

Left ({HISMAST.STOCK_CATEGORY} + space (2), 2)


 You were converting "A" to "  A" and the taking the rightmost 2 characters - " A".
 The second version converts "A" to "A  " and takes the leftmost 2 characters - "A ".

 James
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question