Concatenation

sebekkg

New member
Local time
Today, 09:09
Joined
Apr 22, 2017
Messages
4
Hello guys can you help me on one issue.

For example i have some text fields that i want to represent differently.

They are like this example z564640 54331 but i want them to be 8 in length and if they are shorter it needs to add one or more 0 in front

So from z564640 to 0z564640 and 54331 would be 00054331.

Thanks in advance.

Sent from my SM-N9005 using Tapatalk
 
Formatting a number to prefix with 0's is simple with: Format(54331, "00000000")

However, throwing in alphas fails.

Will there always be 7 characters when an alpha is present? Maybe:

0 & Format([Fieldname], "0000000")

Manipulating text requires consistency in structure. If it gets much more complicated (inconsistent structure), build a custom function.
 
It is numeric or alfa numeric. "Z" in front or "hz" in front.

Sent from my SM-N9005 using Tapatalk
 
Actually, there is. Just remembered some code I have used for this.

Let x represent your field.

String(8-Len(x), "0") & x
 
Let's say that the magic number of characters you need is represented by MN and the input string is INPS and the output string is OUTPS

Code:
OUTPS = Right( ( String( MN, "0" ) & Trim$( INPS ) ), MN )

This should work correctly even if INPS is null or an empty string or a sequence of blanks. I added a technically unneeded pair of parentheses just to clarify the expression grouping.
 

Users who are viewing this thread

Back
Top Bottom