Passing a string of 108 characters

MarionD

Registered User.
Local time
Today, 10:18
Joined
Oct 10, 2000
Messages
425
I'm trying to write a text file as an export spec. Can anyone help me on this:

I need to export exactly 108 Characters.

Left(Format(recs!(Buchungstext), 108)) works fine as long as the text is longer than 108 Characters. When it is shorter, I need to fill out the 108 spaces as blanks, so tha the string is 108 characters.
Thanks so much
Marion
 
Something like this should work:


Code:
dim mySTR as string
dim i as integer

if len(Format(recs!(Buchungstext))) > 108 then
Left(Format(recs!(Buchungstext), 108))
else
mySTR = (Format(recs!(Buchungstext)))
for i = len(Format(recs!(Buchungstext))) to 108
mySTR = mySTR & " "
next i
end if
 
I would think that:
Left(recs!(Buchungstext) & Space(108), 108)
would work as well.
 
Ooh never seen the space function before and certainly better than using my code.
 
Thanks to both for the replies.

Would the space not use the Text + space 108? That is if the text were 50 Characters long would the end result not be 50 + 108 instead of just 108 including the 50 (50 + space(58))
 
MarionD, if you use the expression provided by RuralGuy, you will get the required result. Let's examine the Left function:
Microsoft Visual Basic Help said:
Left Function

Returns a Variant (String) containing a specified number of characters from the left side of a string.

Syntax

Left(string, length)


The Left function syntax has these named arguments:

Part Description
string Required. String expression from which the leftmost characters are returned. If string contains Null, Null is returned.

length Required; Variant (Long). Numeric expression indicating how many characters to return. If 0, a zero-length string ("") is returned. If greater than or equal to the number of characters in string, the entire string is returned.

Thus:
Code:
Left(recs!(Buchungstext) & Space(108), 108)
...takes the concatenated result of recs!(Buchungstext) & Space(108), and only returns the leftmost 108 characters.
 
Thank you very very much for the explanation - it really helps when one understands what you're doing!

Marion
 
oops! another problem! If there is nothing in the field, I still need 108 spaces to be returned not a zero length string. Could one get round thid with the nz function somehow? Although I dont want a 0 returned?
 
nz() does not have to return a 0 as the second parameter is optional and for numeric fields is usually set to 0 and strings ""
 
The code I supplied will return 108 spaces if the field is null.
 

Users who are viewing this thread

Back
Top Bottom