string formatting...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I want to concatenate two text fields together. Once is 20 char and the
other is 10. I do not want them "trimmed" - I want to concatenate based on
teh full length of the string...

Example...

rs!Field1 = "Field1 Length 20"
rs!Field2 = "Field2 Length 20"

I do NOT want the concatenated result to be...
"Field1 Length 20Field2 Length 20"

I DO want the result to be...
"Field1 Length 20 Field2 Length 20 "

How would one accomplish this?

Thanks,

Brad
 
Brad said:
I want to concatenate two text fields together. Once is 20 char and
the other is 10. I do not want them "trimmed" - I want to concatenate
based on teh full length of the string...

Example...

rs!Field1 = "Field1 Length 20"
rs!Field2 = "Field2 Length 20"

I do NOT want the concatenated result to be...
"Field1 Length 20Field2 Length 20"

I DO want the result to be...
"Field1 Length 20 Field2 Length 20 "

How would one accomplish this?

Thanks,

Brad

Sorry, you'll have to try again. I have no idea what that final result is
supposed to mean. The result you say you don't want is 32 characters long
and the one you say you do want is 39 characters long. I don't see how you
get there when starting with fields that are 20 and 10 characters long.
 
Sorry about that - typo... Each field 20 chars long...

The concatenated string I want should be the full 20 chars for each field,
in other words I want the trailing spaces left in - at least for the first
field so that the concatenation of two 20 char fields whose values both
contain "test" would look something like...

"test test "
OR
"test test"


NOT

"testtest"

Is that a little more clear?

Thanks

Brad
 
Is this a trick question?
concatenating strings does not trim them; however, if you store a variable
in a table field and the field is defined as 20 characters, but the varialbe
is only 10 characters, when you retrieve the value from the table field, you
will only get 10 back. Access does not pad the field.

So, to use your example of "Test Test ", you
will have to do the padding yourself.

strResult1 = rs!FIELD1
strResult2 = rs!FIELD2

strFinalResult = strResult1 & Space(20 - Len(strResult1)) _
& strResult2 & Space(20 - Len(strResult2))
 
Sorry about the syntax of my question - but you answered it anyway... The
old "space" function - that is what I was looking for. I remember that one
from dbase and Clipper years ago.. This was all I wanted to know - I was
just thinking there may have been a function that incoproated the "space" in
it that you could get the full length of the field including the difference
between the actual length and the db field length...

Thanks
 
Not in Access (wish there was) In FoxPro there is a Pad function that does
that.
I guess I should have sent my own simple version along:

Function FixLen(strToFix As String, intLen As Integer, strPad As String) As
String
'Returns a string that is formatted to a specificed length with a specified
character
'Returns the original string if it is >= to intLen
'strToFix - The string you want to be padded
'intLen - The desired total length of the results
'strPad - The character to pad the string with (will only use the first
character if
' it is longer than 1 character or 1 space if strpad = ""
Dim strToPass As String
If Len(strPad) = 0 Then
strPad = " "
Else
strPad = Left(strPad, 1)
End If
If Len(strToFix) >= intLen Then
strToPass = strToFix
Else
strToPass = strToFix & String(intLen - Len(strToFix), strPad)
End If
FixLen = strToPass
End Function
 
I can't resist jumping in, because this is the first time I've ever in
my life found a use for the Mid statement:

Public Function ConcatFix(String1 As String, String2 As String)
Dim Buf As String * 40

LSet Buf = String1
Mid(Buf, 21, Len(String2)) = String2
ConcatFix = Buf
End Function
 
Back
Top