Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write a fixed string 1

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
i need to write into a txt a filed with:

first line
Nome (max lenght of string 50) &" " "& Cognome (max lenght of string 50)
second line
Indirizzo (max lenght of string 40) &" " "& Citta (max lenght of string 30)
ecc...

the rest of string are filled with space and to the and each line and Carriage return(cr+lf)

to the and:
Mario + 45 space Rossi + 45 space
Via Roma,2 + 31 space Napoli + 24 space
 
first line[tt]
Nome & Space(50 – Len(Nome)) & " " & Cognome & Space(50 – Len(Cognome))[/tt]
second line[tt]
Indirizzo & Space(40 – Len(Indirizzo)) & " " & Citta & Space(30 – Len(Citta))[/tt]


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
People forget that the Print function has the ability to insert text at absolute column positions (a relic of the time when you could position the cursor at an absolute row and column position on a character terminal). In which case. if the out put of Andy's code is what yoiu are looking for, it could also be done as:

Code:
[blue]    hFile = FreeFile()
    
    Open "<yourfilename>" For Output As FreeFile
    
    Print #hFile, nome; Tab(50); cognome; Tab(100)
    Print #hFile, indirizzo; Tab(40); citta; Tab(70)
    
    Close #hFile[/blue]


 
Good to know, although not very intuitive and a little confusing.
I would think Tab(100) would add 100 Tabs, and not pad the line with spaces.


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
HI strong, but i need to append the current line in existng other lines in my.txt...
 
>I would think Tab(100)

Ah - but that is because you have clearly never read the Tab documentation, Andy ... ;-)
 
>i need to append the current line in existng other lines in my.txt...

As previously advised, I don't necessarily provide fully worked coding solutions to peoples problems, Rather I generally provide an illustration of how something might be achieved, then leave it up to the originator of the question to work that back into their projects. So my example here was to illustrate how one might use tab(n) rather than building appropriate strings. it is NOT an example of file i/o - which I'd kind of assumed as a programmer you'd have a handle on. Still here's the complex change need to make it append ...

Code:
[blue]    hFile = FreeFile()
    
    Open "<yourfilename>" For [b]Append[/b] As FreeFile
    
    Print #hFile, nome; Tab(50); cognome; Tab(100)
    Print #hFile, indirizzo; Tab(40); citta; Tab(70)
    
    Close #hFile [/blue]
 
@strongm, just a query because I've not done it for years but can you not just declare the strings as fixed length?

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top