Read / write file "INI"

Every evening -

I am looking for some thoughts on how to read / write values ​​from a windows ini structured file. I have a settings file created with another application, and I would like to update the key values ​​in the specified section. I got it working using the buffer.replace process, but now I understand that some keys are used in partitions and global replacement of the value will cause problems.

Here is an example of what my ini file looks like

IMPORT-1] SETTINGS="HELLO" FILENAME="C:\TEST\TEST1.CSV" [ENCODE-2] FILENAME="C:\TEST\REPORT1.XPS" 

I have dozens of blocks, so any clarity in reading and writing to a value in a particular section will be greatly appreciated!

- Greetings and thanks to George

+4
source share
1 answer

You can use some of the kernel32 functions.

 Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _ ByVal lpKeyName As String, _ ByVal lpDefault As String, _ ByVal lpReturnedString As StringBuilder, _ ByVal nSize As Integer, _ ByVal lpFileName As String) As Integer 

This will allow you to read the ini file.

 Dim sb As StringBuilder sb = New StringBuilder(500) GetPrivateProfileString("IMPORT-1", "SETTINGS", "", sb, sb.Capacity, "test.ini") 
+7
source

Source: https://habr.com/ru/post/1482770/


All Articles