Newbie: creating a fixed-line-length file from a variable-line-length file
Author |
Message |
I Haw #1 / 10
|
 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 |
|
 |
Phill W #2 / 10
|
 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 |
|
 |
I Haw #3 / 10
|
 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 |
|
 |
Phill W #4 / 10
|
 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 |
|
 |
J Fren #5 / 10
|
 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 |
|
 |
I Haw #6 / 10
|
 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 |
|
 |
J Fren #7 / 10
|
 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 |
|
 |
I Haw #8 / 10
|
 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 |
|
 |
Phill W #9 / 10
|
 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.
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 |
|
 |
J Fren #10 / 10
|
 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 |
|
|
|