Newbie: creating a fixed-line-length file from a variable-line-length file 
Author Message
 Newbie: creating a fixed-line-length file from a variable-line-length file

I've been trying to create a program that will create fixed-line-length files
from variable-line-length files where the longest-line-length of the variable
file is used for the fixed-line-length of the output file.  I tried the
following for a file where the longest-line-length of 70, but it doesn't work:

Dim oneline As String * 70
Open "test.txt.variable" For Input As #1
Open "test.txt.fixed" For Append As #2
Do While Not EOF(1)
    Input #1, oneline
    Write #2, oneline
Loop
Close #1
Close #2

It increases the line-length of this file to 75 and adds double quotes to the
beginning and ending of each line.  Also, if there is a comma within the line
it treats it as a field separator instead of part of the text and separates
that line into 2 lines in the output file.  Any suggestions?



Fri, 19 Dec 2003 23:49:54 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file

Try this instead

    Line Input #1, oneline
    Print #2, oneline

And try to use FreeFile to get the next available file handle, rather than
hard coding them.

HTH,
    Phill  W.


Quote:
> I've been trying to create a program that will create fixed-line-length
files
> from variable-line-length files where the longest-line-length of the
variable
> file is used for the fixed-line-length of the output file.  I tried the
> following for a file where the longest-line-length of 70, but it doesn't
work:

> Dim oneline As String * 70
> Open "test.txt.variable" For Input As #1
> Open "test.txt.fixed" For Append As #2
> Do While Not EOF(1)
>     Input #1, oneline
>     Write #2, oneline
> Loop
> Close #1
> Close #2

> It increases the line-length of this file to 75 and adds double quotes to
the
> beginning and ending of each line.  Also, if there is a comma within the
line
> it treats it as a field separator instead of part of the text and
separates
> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 00:06:57 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file
Thanks, but what is FreeFile?  There's no reference to it in my VB6 book's
index.



Quote:

>Try this instead

>    Line Input #1, oneline
>    Print #2, oneline

>And try to use FreeFile to get the next available file handle, rather than
>hard coding them.

>HTH,
>    Phill  W.



>> I've been trying to create a program that will create fixed-line-length
>files
>> from variable-line-length files where the longest-line-length of the
>variable
>> file is used for the fixed-line-length of the output file.  I tried the
>> following for a file where the longest-line-length of 70, but it doesn't
>work:

>> Dim oneline As String * 70
>> Open "test.txt.variable" For Input As #1
>> Open "test.txt.fixed" For Append As #2
>> Do While Not EOF(1)
>>     Input #1, oneline
>>     Write #2, oneline
>> Loop
>> Close #1
>> Close #2

>> It increases the line-length of this file to 75 and adds double quotes to
>the
>> beginning and ending of each line.  Also, if there is a comma within the
>line
>> it treats it as a field separator instead of part of the text and
>separates
>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 00:18:33 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file
From MSDN,

FreeFile Function

Returns an Integer representing the next file number available for use by
the Open statement.

Syntax

FreeFile[(rangenumber)]

The optional range number argument is a Variant that specifies the range
from which the next free file number is to be returned. Specify a 0
(default) to return a file number in the range 1 - 255, inclusive. Specify a
1 to return a file number in the range 256 - 511.

Remarks

Use FreeFile to supply a file number that is not already in use.

Regards,
    Phill  W.


Quote:
> Thanks, but what is FreeFile?  There's no reference to it in my VB6 book's
> index.



Sat, 20 Dec 2003 00:39:27 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file
FreeFile gets a Free File Number

ie:

  Channel = FreeFile
  Open "MyFile.txt" For Output As #Channel

Your code should read :-

   OutText = Space$( 70 )
   While EOF( InChannel ) = 0
             Line Input# InChannel, S$
             LSet OutText = S$
             Print# OutChannel, OutText
   Wend

Quote:

>Thanks, but what is FreeFile?  There's no reference to it in my VB6 book's
>index.



>>Try this instead

>>    Line Input #1, oneline
>>    Print #2, oneline

>>And try to use FreeFile to get the next available file handle, rather than
>>hard coding them.

>>HTH,
>>    Phill  W.



>>> I've been trying to create a program that will create fixed-line-length
>>files
>>> from variable-line-length files where the longest-line-length of the
>>variable
>>> file is used for the fixed-line-length of the output file.  I tried the
>>> following for a file where the longest-line-length of 70, but it doesn't
>>work:

>>> Dim oneline As String * 70
>>> Open "test.txt.variable" For Input As #1
>>> Open "test.txt.fixed" For Append As #2
>>> Do While Not EOF(1)
>>>     Input #1, oneline
>>>     Write #2, oneline
>>> Loop
>>> Close #1
>>> Close #2

>>> It increases the line-length of this file to 75 and adds double quotes to
>>the
>>> beginning and ending of each line.  Also, if there is a comma within the
>>line
>>> it treats it as a field separator instead of part of the text and
>>separates
>>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 00:52:02 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file
Thanks for the code, but I'm afraid I don't understand what variables with $'s
are - there is no reference to them in my VB6 book.  Is there somewhere on the
web where this is explained?
Quote:

>FreeFile gets a Free File Number

>ie:

>  Channel = FreeFile
>  Open "MyFile.txt" For Output As #Channel

>Your code should read :-

>   OutText = Space$( 70 )
>   While EOF( InChannel ) = 0
>             Line Input# InChannel, S$
>             LSet OutText = S$
>             Print# OutChannel, OutText
>   Wend


>>Thanks, but what is FreeFile?  There's no reference to it in my VB6 book's
>>index.



>>>Try this instead

>>>    Line Input #1, oneline
>>>    Print #2, oneline

>>>And try to use FreeFile to get the next available file handle, rather than
>>>hard coding them.

>>>HTH,
>>>    Phill  W.



>>>> I've been trying to create a program that will create fixed-line-length
>>>files
>>>> from variable-line-length files where the longest-line-length of the
>>>variable
>>>> file is used for the fixed-line-length of the output file.  I tried the
>>>> following for a file where the longest-line-length of 70, but it doesn't
>>>work:

>>>> Dim oneline As String * 70
>>>> Open "test.txt.variable" For Input As #1
>>>> Open "test.txt.fixed" For Append As #2
>>>> Do While Not EOF(1)
>>>>     Input #1, oneline
>>>>     Write #2, oneline
>>>> Loop
>>>> Close #1
>>>> Close #2

>>>> It increases the line-length of this file to 75 and adds double quotes to
>>>the
>>>> beginning and ending of each line.  Also, if there is a comma within the
>>>line
>>>> it treats it as a field separator instead of part of the text and
>>>separates
>>>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 00:59:25 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file

   Dim S As String
   Dim OutText As String

   OutText = Space( 70 )
   While EOF( InChannel ) = 0
            Line Input# InChannel, S
            LSet OutText = S
            Print# OutChannel, OutText
  Wend

$ means String

Dim S$
  is the same as
      Dim S As String

This is basic BASIC stuff - it is part of the original specification

If you look at any decent guys's code, say Dan Appleman, Bruce
McKinney, the MS Web Sites, www.AllAPI.net

then you will find & and $ used as abreviations.

If it is good enough for them - then it is good enough for me.

Just think of it as 'Reverse Hungarian'

Quote:

>Thanks for the code, but I'm afraid I don't understand what variables with $'s
>are - there is no reference to them in my VB6 book.  Is there somewhere on the
>web where this is explained?


>>FreeFile gets a Free File Number

>>ie:

>>  Channel = FreeFile
>>  Open "MyFile.txt" For Output As #Channel

>>Your code should read :-

>>   OutText = Space$( 70 )
>>   While EOF( InChannel ) = 0
>>             Line Input# InChannel, S$
>>             LSet OutText = S$
>>             Print# OutChannel, OutText
>>   Wend


>>>Thanks, but what is FreeFile?  There's no reference to it in my VB6 book's
>>>index.



>>>>Try this instead

>>>>    Line Input #1, oneline
>>>>    Print #2, oneline

>>>>And try to use FreeFile to get the next available file handle, rather than
>>>>hard coding them.

>>>>HTH,
>>>>    Phill  W.



>>>>> I've been trying to create a program that will create fixed-line-length
>>>>files
>>>>> from variable-line-length files where the longest-line-length of the
>>>>variable
>>>>> file is used for the fixed-line-length of the output file.  I tried the
>>>>> following for a file where the longest-line-length of 70, but it doesn't
>>>>work:

>>>>> Dim oneline As String * 70
>>>>> Open "test.txt.variable" For Input As #1
>>>>> Open "test.txt.fixed" For Append As #2
>>>>> Do While Not EOF(1)
>>>>>     Input #1, oneline
>>>>>     Write #2, oneline
>>>>> Loop
>>>>> Close #1
>>>>> Close #2

>>>>> It increases the line-length of this file to 75 and adds double quotes to
>>>>the
>>>>> beginning and ending of each line.  Also, if there is a comma within the
>>>>line
>>>>> it treats it as a field separator instead of part of the text and
>>>>separates
>>>>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 02:01:38 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file
Oh, now I understand. Thanks!
Quote:

>   Dim S As String
>   Dim OutText As String

>   OutText = Space( 70 )
>   While EOF( InChannel ) = 0
>            Line Input# InChannel, S
>            LSet OutText = S
>            Print# OutChannel, OutText
>  Wend

>$ means String

>Dim S$
>  is the same as
>      Dim S As String

>This is basic BASIC stuff - it is part of the original specification

>If you look at any decent guys's code, say Dan Appleman, Bruce
>McKinney, the MS Web Sites, www.AllAPI.net

>then you will find & and $ used as abreviations.

>If it is good enough for them - then it is good enough for me.

>Just think of it as 'Reverse Hungarian'


>>Thanks for the code, but I'm afraid I don't understand what variables with $'s

>>are - there is no reference to them in my VB6 book.  Is there somewhere on the

>>web where this is explained?


>>>FreeFile gets a Free File Number

>>>ie:

>>>  Channel = FreeFile
>>>  Open "MyFile.txt" For Output As #Channel

>>>Your code should read :-

>>>   OutText = Space$( 70 )
>>>   While EOF( InChannel ) = 0
>>>             Line Input# InChannel, S$
>>>             LSet OutText = S$
>>>             Print# OutChannel, OutText
>>>   Wend


>>>>Thanks, but what is FreeFile?  There's no reference to it in my VB6 book's
>>>>index.




>>>>>Try this instead

>>>>>    Line Input #1, oneline
>>>>>    Print #2, oneline

>>>>>And try to use FreeFile to get the next available file handle, rather than
>>>>>hard coding them.

>>>>>HTH,
>>>>>    Phill  W.



>>>>>> I've been trying to create a program that will create fixed-line-length
>>>>>files
>>>>>> from variable-line-length files where the longest-line-length of the
>>>>>variable
>>>>>> file is used for the fixed-line-length of the output file.  I tried the
>>>>>> following for a file where the longest-line-length of 70, but it doesn't
>>>>>work:

>>>>>> Dim oneline As String * 70
>>>>>> Open "test.txt.variable" For Input As #1
>>>>>> Open "test.txt.fixed" For Append As #2
>>>>>> Do While Not EOF(1)
>>>>>>     Input #1, oneline
>>>>>>     Write #2, oneline
>>>>>> Loop
>>>>>> Close #1
>>>>>> Close #2

>>>>>> It increases the line-length of this file to 75 and adds double quotes to
>>>>>the
>>>>>> beginning and ending of each line.  Also, if there is a comma within the
>>>>>line
>>>>>> it treats it as a field separator instead of part of the text and
>>>>>separates
>>>>>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 02:05:48 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file
OK, I'll bite.

Why bother with LSet?
Just assigning a [variable length] string to a fixed length string does the
space padding, doesn't it?

Regards,
    Phill  W.


Quote:

>    Dim S As String
>    Dim OutText As String

>    OutText = Space( 70 )
>    While EOF( InChannel ) = 0
>             Line Input# InChannel, S
>             LSet OutText = S
>             Print# OutChannel, OutText
>   Wend

> $ means String

> Dim S$
>   is the same as
>       Dim S As String

> This is basic BASIC stuff - it is part of the original specification

> If you look at any decent guys's code, say Dan Appleman, Bruce
> McKinney, the MS Web Sites, www.AllAPI.net

> then you will find & and $ used as abreviations.

> If it is good enough for them - then it is good enough for me.

> Just think of it as 'Reverse Hungarian'


> >Thanks for the code, but I'm afraid I don't understand what variables
with $'s
> >are - there is no reference to them in my VB6 book.  Is there somewhere
on the
> >web where this is explained?


> >>FreeFile gets a Free File Number

> >>ie:

> >>  Channel = FreeFile
> >>  Open "MyFile.txt" For Output As #Channel

> >>Your code should read :-

> >>   OutText = Space$( 70 )
> >>   While EOF( InChannel ) = 0
> >>             Line Input# InChannel, S$
> >>             LSet OutText = S$
> >>             Print# OutChannel, OutText
> >>   Wend


> >>>Thanks, but what is FreeFile?  There's no reference to it in my VB6
book's
> >>>index.




- Show quoted text -

Quote:


> >>>>Try this instead

> >>>>    Line Input #1, oneline
> >>>>    Print #2, oneline

> >>>>And try to use FreeFile to get the next available file handle, rather
than
> >>>>hard coding them.

> >>>>HTH,
> >>>>    Phill  W.



> >>>>> I've been trying to create a program that will create
fixed-line-length
> >>>>files
> >>>>> from variable-line-length files where the longest-line-length of the
> >>>>variable
> >>>>> file is used for the fixed-line-length of the output file.  I tried
the
> >>>>> following for a file where the longest-line-length of 70, but it
doesn't
> >>>>work:

> >>>>> Dim oneline As String * 70
> >>>>> Open "test.txt.variable" For Input As #1
> >>>>> Open "test.txt.fixed" For Append As #2
> >>>>> Do While Not EOF(1)
> >>>>>     Input #1, oneline
> >>>>>     Write #2, oneline
> >>>>> Loop
> >>>>> Close #1
> >>>>> Close #2

> >>>>> It increases the line-length of this file to 75 and adds double
quotes to
> >>>>the
> >>>>> beginning and ending of each line.  Also, if there is a comma within
the
> >>>>line
> >>>>> it treats it as a field separator instead of part of the text and
> >>>>separates
> >>>>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 17:09:15 GMT  
 Newbie: creating a fixed-line-length file from a variable-line-length file



Quote:
>OK, I'll bite.

>Why bother with LSet?
>Just assigning a [variable length] string to a fixed length string does the
>space padding, doesn't it?

Yes it does - but I would always use the LSet as it 'self documents'
my own code.

I also avoid using fixed length strings except in UDTs

Quote:

>Regards,
>    Phill  W.



>>    Dim S As String
>>    Dim OutText As String

>>    OutText = Space( 70 )
>>    While EOF( InChannel ) = 0
>>             Line Input# InChannel, S
>>             LSet OutText = S
>>             Print# OutChannel, OutText
>>   Wend

>> $ means String

>> Dim S$
>>   is the same as
>>       Dim S As String

>> This is basic BASIC stuff - it is part of the original specification

>> If you look at any decent guys's code, say Dan Appleman, Bruce
>> McKinney, the MS Web Sites, www.AllAPI.net

>> then you will find & and $ used as abreviations.

>> If it is good enough for them - then it is good enough for me.

>> Just think of it as 'Reverse Hungarian'


>> >Thanks for the code, but I'm afraid I don't understand what variables
>with $'s
>> >are - there is no reference to them in my VB6 book.  Is there somewhere
>on the
>> >web where this is explained?


>> >>FreeFile gets a Free File Number

>> >>ie:

>> >>  Channel = FreeFile
>> >>  Open "MyFile.txt" For Output As #Channel

>> >>Your code should read :-

>> >>   OutText = Space$( 70 )
>> >>   While EOF( InChannel ) = 0
>> >>             Line Input# InChannel, S$
>> >>             LSet OutText = S$
>> >>             Print# OutChannel, OutText
>> >>   Wend


>> >>>Thanks, but what is FreeFile?  There's no reference to it in my VB6
>book's
>> >>>index.




>> >>>>Try this instead

>> >>>>    Line Input #1, oneline
>> >>>>    Print #2, oneline

>> >>>>And try to use FreeFile to get the next available file handle, rather
>than
>> >>>>hard coding them.

>> >>>>HTH,
>> >>>>    Phill  W.



>> >>>>> I've been trying to create a program that will create
>fixed-line-length
>> >>>>files
>> >>>>> from variable-line-length files where the longest-line-length of the
>> >>>>variable
>> >>>>> file is used for the fixed-line-length of the output file.  I tried
>the
>> >>>>> following for a file where the longest-line-length of 70, but it
>doesn't
>> >>>>work:

>> >>>>> Dim oneline As String * 70
>> >>>>> Open "test.txt.variable" For Input As #1
>> >>>>> Open "test.txt.fixed" For Append As #2
>> >>>>> Do While Not EOF(1)
>> >>>>>     Input #1, oneline
>> >>>>>     Write #2, oneline
>> >>>>> Loop
>> >>>>> Close #1
>> >>>>> Close #2

>> >>>>> It increases the line-length of this file to 75 and adds double
>quotes to
>> >>>>the
>> >>>>> beginning and ending of each line.  Also, if there is a comma within
>the
>> >>>>line
>> >>>>> it treats it as a field separator instead of part of the text and
>> >>>>separates
>> >>>>> that line into 2 lines in the output file.  Any suggestions?



Sat, 20 Dec 2003 18:48:52 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. ? Text Box: multi line; fixed length per line

2. Insert Variable Number of Spaces into line to Create Fixed column file

3. Limit line length in opened files

4. Building a fixed length ASCII text file out of wrapping file

5. Limitting line length of each line within multiline textbox

6. converting a varible length record to a fixed length rec

7. ADOX: Extending a fixed length Jet string field length

8. exporting to fixed-length files

9. Access translation to fixed length ACII file

10. Delimited/fixed length file manipulation

11. Fixed-length formatted text files...

12. Text File (fixed-length) to load Table

 

 
Powered by phpBB® Forum Software