Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Indent a long string into a txt file
Message
 
 
To
02/05/2022 13:10:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01684311
Message ID:
01684329
Views:
38
>>>>>>>>>Hi,
>>>>>>>>>
>>>>>>>>>The code writes a long string (it could be up to 200 or more characters) into a .txt file. The string is written to the .txt file using strtofile() function. I would like the long string to be indented by, say 10 characters. I can indent the first line, by adding a space(10). But the rest of the string go to the 1st column,
>>>>>>>>>Is there a way to do it, other than parsing the string into 60-70 characters and adding a space(10) before each line?
>>>>>>>>>
>>>>>>>>>TIA
>>>>>>>>
>>>>>>>>Sorry for a newbie question. I think VFP has a function that will populate an array from a long string, setting the max number of characters in each element. If my memory services me right, what is this function?
>>>>>>>>Basically I want the VFP to parse the string into smaller strings, each one no more than 60 char in length.
>>>>>>>>TIA
>>>>>>>
>>>>>>>AFAIK there's no such function.
>>>>>>
>>>>>>I suppose since I didn't remember this function, my memory works :)
>>>>>
>>>>>Right. 😂
>>>>
>>>>I think I found it: memlines() and mline()
>>>
>>>Not quite what you asked for, but may be useful.
>>>
>>>Anyway, I am convinced that my first advice is the easiest to implement. If you don't understand my idea and/or want me to assist you, feel free to send me an email with realistic data. Should be a fun challenge.
>>
>>Thank you for your offer. If my approach does not work, I may take you up on your offer.
>
>This code does the job. Note that most of the code is probably redundant. It checks the parameters, takes care of setting the necessary parameters and resetting them.
>
>The last line was added for testing.
>
>
>*dmitry.prg
>Lparameters tcText, tcFileName, tnMargin, tnMaxLength
>If Pcount()<4
>  m.tnMaxLength = 60
>Endif
>If Pcount()<3
>  m.tnMargin = 10
>EndIf
>If Empty(m.tcFileName) or Vartype(m.tcFileName)#'C'
>  messagebox('No filename given')
>  Return .F.
>Endif
>If Empty(m.tcText) or Vartype(m.tcText)#'C'
>  messagebox('No text given')
>  Return .F.
>EndIf
>lnMargin = Set("Margin")
>Set Margin To m.tnMargin 
>tnMemo=Set("Memowidth")
>Set Memowidth To m.tnMaxLength - m.tnMargin 
>lcPrinter = Set("Printer",1)
>llPrinter = Set("Printer")
>llEcho = Set("Echo")
>llConsole = Set("Console")
>Set printer to file (m.tcFileName)
>Set printer on
>Set echo off
>Set Console off
>??m.tcText 
>Set Printer &llPrinter
>Set Echo &llEcho
>Set Console &llConsole 
>Set Margin To m.lnMargin
>Set Memowidth To m.tnMemo 
>Set Printer to (m.lcPrinter)
>Modify File (m.tcFileName)
>
Thank you for the code.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform