Question about print string to text file

Question about print string to text file

neam
Collaborator Collaborator
613 Views
8 Replies
Message 1 of 9

Question about print string to text file

neam
Collaborator
Collaborator

HI everyone:
It is possible to specify in which column (notepad) the last word should be written during the construction of a string.
for example for write "CHECKPOINT 1" at column 70


(setq txterr1 (strcat groupname " & R1=" (rtos (cadr r1) 2 2)          "CHECKPOINT 1"))
                       \______________     __________________/          --> start write checkpoint at column 70
                                                         \/
                            This length is variable < column 70


(setq txterr2 (strcat groupname " & R2=" (rtos (cadr r2) 2 2)           "CHECKPOINT 2"))
                       \______________     __________________/            --> start write checkpoint at column 70
                                                         \/
                            This length is variable < column 70

0 Likes
Accepted solutions (2)
614 Views
8 Replies
Replies (8)
Message 2 of 9

Moshe-A
Mentor
Mentor

@neam hi,

 

Text file is based on record lines all string.

When a text file is open, the pointer is places on positon 1,1 which is line 1 character 1. To advance the pointer you have write characters string. To start writing at position 71, start by writing 70 spaces before.

 

Moshe

 

 

0 Likes
Message 3 of 9

neam
Collaborator
Collaborator

Dear Moshe

Thank you for reply

the first section of text string (Groupname and Reduce of circle) are variable length.

sometimes 20 character or 33 character ............ but it must be less than 70 characters.

0 Likes
Message 4 of 9

Moshe-A
Mentor
Mentor

@neam

 

First why you are restricted to 70?

Second you can monitor the number of characters when 70 reached, drop the rest characters or those less important.

 

Moshe

0 Likes
Message 5 of 9

neam
Collaborator
Collaborator

We have a program in office written in Visual Basic.
which takes the output information from the map and performs a series of analyzes on them.
it reads the checkpoint in column 70.
How to monitor character 70?
I would appreciate it if you could explain.

0 Likes
Message 6 of 9

Moshe-A
Mentor
Mentor
Accepted solution

@neam ,

 

here is an example function (record_format) that accepts 2 strings arguments

the first a string strEnd@70 and the second  strStart@70

the trick here is the first string which will be format as (1- 70) characters no matter it's length.

if its length is less than (1- 70) , a spaces will be added. the second string is always start at 70

 

note, a const STRSIZE is set to 70,  if you want to change it a bit, go head.

the return value of (record_format) is a line string ready to written to file.

 

hope you know how to read a string directly from character 70 😀

 

enjoy

Moshe

 

; Arguments
; strStopAt70 - pefix string to be end on character (1- STRSIZE)
; strStart@70 - suffix string to start on character STRSIZE
; Return record line
(defun record_format (strEnd@70  strStart@70 / spaces STRSIZE)

 (defun spaces (s)
  (cond
   ((> (strlen s) (1- STRSIZE))
    (substr s 1 (1- STRSIZE))
   ); case
   (t
    (repeat (- (1- STRSIZE) (strlen s))
     (setq s (strcat s " "))
    )
    s
   )
  ); cond
 ); spaces

 (setq STRSIZE 70); const
 (strcat (spaces strEnd@70) strStart@70) 
);  record_format

 

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

(setq spaces ""); initially empty string

(repeat (- 69 (strlen txterr1)) (setq spaces (strcat spaces " "))); build required # of spaces

(write-line (strcat txterr1 spaces "CHECKPOINT 1") yourFileName); build result to write out

Kent Cooper, AIA
0 Likes
Message 8 of 9

neam
Collaborator
Collaborator

THX you verrrrrrrry much dear Moshe

0 Likes
Message 9 of 9

neam
Collaborator
Collaborator

THX you verrrrrrrry much dear Kent1Cooper

0 Likes