×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Write a fixed string

Write a fixed string

Write a fixed string

(OP)
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

RE: Write a fixed string

first line
Nome & Space(50 – Len(Nome)) & " " & Cognome & Space(50 – Len(Cognome))

second line
Indirizzo & Space(40 – Len(Indirizzo)) & " " & Citta & Space(30 – Len(Citta))



---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Write a fixed string

tks Andrzejek

RE: Write a fixed string

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

    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 


RE: Write a fixed string

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

RE: Write a fixed string

HI strong, but i need to append the current line in existng other lines in my.txt...

RE: Write a fixed string

>I would think Tab(100)

Ah - but that is because you have clearly never read the Tab documentation, Andy ... winky smile

RE: Write a fixed string

>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

    hFile = FreeFile()
    
    Open "<yourfilename>" For Append As FreeFile
    
    Print #hFile, nome; Tab(50); cognome; Tab(100)
    Print #hFile, indirizzo; Tab(40); citta; Tab(70)
    
    Close #hFile  

RE: Write a fixed string

@strongm, just a query because I've not done it for years but can you not just declare the strings as fixed length?

Experience is something you don't get until just after you need it.

RE: Write a fixed string

Yep

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close