-
Edit TXT file
I need to edit a TXT, well actually INI, but basically the same, I need to
be able to *read* the file into memory line at a time, & if the line
contains certain things then I need to change that line. I will also need
to insert new lines sometimes.
Any help is appreciated.
Ammon
--
True Time Phonecards, you get the number of minutes you pay for regardless
of how many calls you make!! 7.9¢ per Minute USA!!
ammon@vac-phonecards.com Contact me for more info.
-
Re: Edit TXT file
One more thing, I need to be able to Return to the top of the file.
Ammon
"amunition" <ammon@vac-phonecards.com> wrote in message
news:3aa44039@news.devx.com...
> I need to edit a TXT, well actually INI, but basically the same, I need to
> be able to *read* the file into memory line at a time, & if the line
> contains certain things then I need to change that line. I will also need
> to insert new lines sometimes.
>
> Any help is appreciated.
> Ammon
>
>
> --
> True Time Phonecards, you get the number of minutes you pay for regardless
> of how many calls you make!! 7.9¢ per Minute USA!!
> ammon@vac-phonecards.com Contact me for more info.
>
>
-
Re: Edit TXT file
Try this
Dim strFile As String
Dim strLines() As String
Dim fnum As Integer
fnum = FreeFile
Open <path & file name> For Binary As fnum
strFile = Space$(LOF(fnum))
Get #fnum, , strFile
Close #fnum
strLines = Split(strFile, vbNewLine)
strFile = "" 'free up memory
Now you have each line in the file in a separate string, so you can just
move up and down through the array to find the line you want and change it.
To add a new line do
ReDim Preserve strLines( LBound(strLines) To UBound(strLines) + 1)
Then
For i = UBound(strLines) To InsertLinePos Step -1
strLines(i) = strLines(i - 1)
Next
strLines(InsertLinePos) = <new text>
To save it do
strFile = Join(strLines(), vbNewLine)
fnum = FreeFile
If Len(Dir(<path & file name>)) Then Kill <path & file name>
Open <path & file name> For Binary As fnum
Put #fnum, , strFile
Close #fnum
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"amunition" <ammon@vac-phonecards.com> wrote in message
news:3aa443f7@news.devx.com...
> One more thing, I need to be able to Return to the top of the file.
>
> Ammon
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa44039@news.devx.com...
> > I need to edit a TXT, well actually INI, but basically the same, I need
to
> > be able to *read* the file into memory line at a time, & if the line
> > contains certain things then I need to change that line. I will also
need
> > to insert new lines sometimes.
> >
> > Any help is appreciated.
> > Ammon
> >
> >
> > --
> > True Time Phonecards, you get the number of minutes you pay for
regardless
> > of how many calls you make!! 7.9¢ per Minute USA!!
> > ammon@vac-phonecards.com Contact me for more info.
> >
> >
>
>
-
Re: Edit TXT file
"amunition" <ammon@vac-phonecards.com> wrote in message
news:3aa443f7@news.devx.com...
> One more thing, I need to be able to Return to the top of the file.
>
> Ammon
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa44039@news.devx.com...
> > I need to edit a TXT, well actually INI, but basically the same, I need
to
To edit an INI you should use the GetPrivateProfileString and
WritePrivateProfileString API calls rather than reading/writing the file
yourself. You should be able to find many examples on the web.
-
Re: Edit TXT file
Thanks, I will look into it, see what I can do.
Ammon
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aa4f22c$1@news.devx.com...
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa443f7@news.devx.com...
> > One more thing, I need to be able to Return to the top of the file.
> >
> > Ammon
> >
> > "amunition" <ammon@vac-phonecards.com> wrote in message
> > news:3aa44039@news.devx.com...
> > > I need to edit a TXT, well actually INI, but basically the same, I
need
> to
>
> To edit an INI you should use the GetPrivateProfileString and
> WritePrivateProfileString API calls rather than reading/writing the file
> yourself. You should be able to find many examples on the web.
>
>
>
-
Re: Edit TXT file
I found some examples, but if the Section already exists then it doesn't
write anything, if the section doesn't exist it writes it alright.
Ammon
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aa4f22c$1@news.devx.com...
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa443f7@news.devx.com...
> > One more thing, I need to be able to Return to the top of the file.
> >
> > Ammon
> >
> > "amunition" <ammon@vac-phonecards.com> wrote in message
> > news:3aa44039@news.devx.com...
> > > I need to edit a TXT, well actually INI, but basically the same, I
need
> to
>
> To edit an INI you should use the GetPrivateProfileString and
> WritePrivateProfileString API calls rather than reading/writing the file
> yourself. You should be able to find many examples on the web.
>
>
>
-
Re: Edit TXT file
One more thing, I need to be able to Return to the top of the file.
Ammon
"amunition" <ammon@vac-phonecards.com> wrote in message
news:3aa44039@news.devx.com...
> I need to edit a TXT, well actually INI, but basically the same, I need to
> be able to *read* the file into memory line at a time, & if the line
> contains certain things then I need to change that line. I will also need
> to insert new lines sometimes.
>
> Any help is appreciated.
> Ammon
>
>
> --
> True Time Phonecards, you get the number of minutes you pay for regardless
> of how many calls you make!! 7.9¢ per Minute USA!!
> ammon@vac-phonecards.com Contact me for more info.
>
>
-
Re: Edit TXT file
Try this
Dim strFile As String
Dim strLines() As String
Dim fnum As Integer
fnum = FreeFile
Open <path & file name> For Binary As fnum
strFile = Space$(LOF(fnum))
Get #fnum, , strFile
Close #fnum
strLines = Split(strFile, vbNewLine)
strFile = "" 'free up memory
Now you have each line in the file in a separate string, so you can just
move up and down through the array to find the line you want and change it.
To add a new line do
ReDim Preserve strLines( LBound(strLines) To UBound(strLines) + 1)
Then
For i = UBound(strLines) To InsertLinePos Step -1
strLines(i) = strLines(i - 1)
Next
strLines(InsertLinePos) = <new text>
To save it do
strFile = Join(strLines(), vbNewLine)
fnum = FreeFile
If Len(Dir(<path & file name>)) Then Kill <path & file name>
Open <path & file name> For Binary As fnum
Put #fnum, , strFile
Close #fnum
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"amunition" <ammon@vac-phonecards.com> wrote in message
news:3aa443f7@news.devx.com...
> One more thing, I need to be able to Return to the top of the file.
>
> Ammon
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa44039@news.devx.com...
> > I need to edit a TXT, well actually INI, but basically the same, I need
to
> > be able to *read* the file into memory line at a time, & if the line
> > contains certain things then I need to change that line. I will also
need
> > to insert new lines sometimes.
> >
> > Any help is appreciated.
> > Ammon
> >
> >
> > --
> > True Time Phonecards, you get the number of minutes you pay for
regardless
> > of how many calls you make!! 7.9¢ per Minute USA!!
> > ammon@vac-phonecards.com Contact me for more info.
> >
> >
>
>
-
Re: Edit TXT file
"amunition" <ammon@vac-phonecards.com> wrote in message
news:3aa443f7@news.devx.com...
> One more thing, I need to be able to Return to the top of the file.
>
> Ammon
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa44039@news.devx.com...
> > I need to edit a TXT, well actually INI, but basically the same, I need
to
To edit an INI you should use the GetPrivateProfileString and
WritePrivateProfileString API calls rather than reading/writing the file
yourself. You should be able to find many examples on the web.
-
Re: Edit TXT file
Thanks, I will look into it, see what I can do.
Ammon
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aa4f22c$1@news.devx.com...
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa443f7@news.devx.com...
> > One more thing, I need to be able to Return to the top of the file.
> >
> > Ammon
> >
> > "amunition" <ammon@vac-phonecards.com> wrote in message
> > news:3aa44039@news.devx.com...
> > > I need to edit a TXT, well actually INI, but basically the same, I
need
> to
>
> To edit an INI you should use the GetPrivateProfileString and
> WritePrivateProfileString API calls rather than reading/writing the file
> yourself. You should be able to find many examples on the web.
>
>
>
-
Re: Edit TXT file
I found some examples, but if the Section already exists then it doesn't
write anything, if the section doesn't exist it writes it alright.
Ammon
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aa4f22c$1@news.devx.com...
>
> "amunition" <ammon@vac-phonecards.com> wrote in message
> news:3aa443f7@news.devx.com...
> > One more thing, I need to be able to Return to the top of the file.
> >
> > Ammon
> >
> > "amunition" <ammon@vac-phonecards.com> wrote in message
> > news:3aa44039@news.devx.com...
> > > I need to edit a TXT, well actually INI, but basically the same, I
need
> to
>
> To edit an INI you should use the GetPrivateProfileString and
> WritePrivateProfileString API calls rather than reading/writing the file
> yourself. You should be able to find many examples on the web.
>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|