Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default How to modify specific lines in a .ini file?

Hello,

When writing multiple values to a .ini file I'm familiar with the
following basic code:

Open "c:\my.ini" For Output As #1
Print #1, "1"
Print #1, "2"
Print #1, "3"
Close #1

Is there a way to modify/write values to specific lines only, for
example modifying the "2" value on line 2 to "5", without overwriting
the other lines with their unchanged values?

Thanks for any feedback!

Jim

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to modify specific lines in a .ini file?


You basically need to open the file and read the file until you get to
the specific row you are looking for then write the new file and close
the file. there are at least 3 methods of accomplishing this.

1) Open the file in Append Mode. The Append Mode will read and write
data to the same file. See webpage below

'OPEN statement'
(http://www.powerbasic.com/support/he..._statement.htm)

2) Open and Input and create a new Output file. Make the changes and
close both files. Then delete the original file. Finaly move the new
file to the old file name.


3) Read the text data into excel putting each row into a single column.
Make the changes you need. Then save the data back into the original
file. the advantage of putting it into a worksheet is you can use the
FIND() method for locating the data you are looking for. Using excel is
less efficient then the other mtwo method becasue it take mor etime and
memory, but writing the code may be easier.

I say may be easier because using excel you would have to read the data
into excel and the output it again which is two extra steps. Also excel
is notorious for for manipulating data when you don't want it to.
Especially reading and writing text data to files. Excel in CSV files
adds double quotes to data (sometimes don't when you do want it to),
performs Text-To-Columns when you don't want it to. I've found lots of
odd things that occur.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=174833

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.misc
external usenet poster
 
Posts: 5,600
Default How to modify specific lines in a .ini file?

Although an ini file is just a plain text file ini files have a structure

[SectionName1]
Keyname1=abc
Keyname2=123

If your ini file is like this all you need to know is the section-name(s)
and key-name(s) you are concerned with (and of course the file-name & path).
APIs GetPrivateProfileString and WritePrivateProfileString to read/write the
values will do all the work for you. I'm sure if you search these terms
together with something like "modify ini file" you will find hundreds of
examples.

Regards,
Peter T

"Jim" wrote in message
...
Hello,

When writing multiple values to a .ini file I'm familiar with the
following basic code:

Open "c:\my.ini" For Output As #1
Print #1, "1"
Print #1, "2"
Print #1, "3"
Close #1

Is there a way to modify/write values to specific lines only, for
example modifying the "2" value on line 2 to "5", without overwriting
the other lines with their unchanged values?

Thanks for any feedback!

Jim



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify specific lines in a .ini file? Jim[_13_] Excel Discussion (Misc queries) 2 January 30th 10 08:35 PM
Modify The Code For Importing Text File into an Excel File vicky Excel Programming 1 December 28th 09 09:47 AM
Create/modify date for specific sheets? Steve Vincent Excel Discussion (Misc queries) 3 September 17th 09 08:25 PM
modify a macro to apply to a specific range of cells Dave F Excel Discussion (Misc queries) 2 April 25th 07 03:00 AM
excel97 vba to append lines to text file overwriting last 2 lines Paul Excel Programming 1 November 6th 04 08:11 PM


All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"