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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I write to a a disk using put and allign a text

Status
Not open for further replies.

ivax

Programmer
Jul 31, 2000
2
ES
I like to allignt a text on a file
 
Ivax,<br><br>Could we have a bit more detail please?<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
I have a type like this<br>type client<br> codbar as string(13)<br> client as string(6) <br> name as string(40)<br>endtype<br><br>and when i write it to disk using Put it makes something like:<br><br>13&nbsp;&nbsp;&nbsp;&nbsp;1029837493827Mike<br><br>and i like write<br>&nbsp;&nbsp;&nbsp;&nbsp;131029837493827&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mike<br><br><br>
 
Could you do something like this?<br><br><FONT FACE=monospace><b><br>.name = &quot;Mike&quot;<br><br>while(length(.name) &lt; 40)<br>&nbsp;&nbsp;&nbsp;&nbsp;.name = &quot; &quot; & .name<br>wend<br></font></b><br><br>Yuk, not very elegant, can someone else do better? &lt;grin&gt; <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Hmmm, maybe.<br><FONT FACE=monospace><b><br>Private Type MyClient<br>&nbsp;&nbsp;&nbsp;&nbsp;codbar As String * 13<br>&nbsp;&nbsp;&nbsp;&nbsp;client As String * 6<br>&nbsp;&nbsp;&nbsp;&nbsp;name As String * 40<br>End Type<br>Dim Client As MyClient<br><br>RSet Client.name = &quot;Mike&quot;<br></font></b><br>Rset right-aligns one string in another string.<br>Visual Basic documentation claims that you can't use it with a user defined type like &quot;Client&quot;. <i>Funny</i>, you know, it just worked for <i>me</i>. :)<br><br><br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Ivax,<br><br>Not sure... tried it at home and it seems to work.&nbsp;&nbsp;Like you, defined a UDT in a module then created a new variable based on the UDT in my form<br><br>ie.<br>Option Explicit<br><br>Public Type client<br>&nbsp;&nbsp;&nbsp;&nbsp;codbar As String * 13<br>&nbsp;&nbsp;&nbsp;&nbsp;client As String * 20<br>&nbsp;&nbsp;&nbsp;&nbsp;name As String * 40<br>End Type<br><br>Then in the form_load I put <br><br>Dim myclient As client<br><br>Open &quot;c:\test.txt&quot; For Random As #1<br><br>With myclient<br>&nbsp;&nbsp;&nbsp;&nbsp;.codbar = 13<br>&nbsp;&nbsp;&nbsp;&nbsp;.client = &quot;123456789&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;.name = &quot;Test&quot;<br>End With<br><br>Put #1, , myclient<br><br>opened it in wordpad and in DOS and it looked correct that is to say, that the codbar was 13 bytes, client was 20 bytes and the name was 40.
 
yup - much better - I'll remember that one. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
I have used this many times.<br><br><br>name = space$(40-len(name)) & name <p>David Paulson<br><a href=mailto: > </a><br><a href= > </a><br>
 
Interesting 'soloutions',&nbsp;&nbsp;I don't understand the need to do the alignment for the text file written to Disc.&nbsp;&nbsp;Could someone please explain this part to me?&nbsp;&nbsp;I am obviously missing some point.<br><br>Michael
 
Micheal,<br><br>Sometimes it is usefull to have a fixed length text file where all the records are consistent in length.&nbsp;&nbsp;The other option would be to have a variable length file but then you would have to have a delimiter at the end of each field.&nbsp;&nbsp;Either way works fine.&nbsp;&nbsp;The delimiter method generally is the better approach when dealing with large text files as it will save tons of space in the long run.&nbsp;&nbsp;But to each their own.&lt;grin&gt;<br>
 
I'm with Micheal.&nbsp;&nbsp;ivax is using put, therefor is this not a random-access file?&nbsp;&nbsp;Then why would you want to read it using a text editor.&nbsp;&nbsp;Whatever class object you write it with will read it.<br>Huh :~*<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top