In Word-VBA I do need to read and write very often to INI files. I want to do the same in Xbasic.
There are a lot of code examples how to read and write INI files in VB but translating so many lines of code I get sleepy. As I'm lazy and like to sleep a lot I like it the quick and dirty way with API functions.
Here is a nice site with very compact information about INI files and the API functions to use.
I've translated two API functions for you and with these two functions you can do everything you want. With this Xbasic example and some time investment of yourself - reading the help and tinker a lot - you can translate the rest of it. But it is not necessary as I said with these two functions you can do everything. If you want to access the WIN.INI you have to translate another two function yourself.
Have fun!
A simple INI file is provided here.
There are a lot of code examples how to read and write INI files in VB but translating so many lines of code I get sleepy. As I'm lazy and like to sleep a lot I like it the quick and dirty way with API functions.
Here is a nice site with very compact information about INI files and the API functions to use.
I've translated two API functions for you and with these two functions you can do everything you want. With this Xbasic example and some time investment of yourself - reading the help and tinker a lot - you can translate the rest of it. But it is not necessary as I said with these two functions you can do everything. If you want to access the WIN.INI you have to translate another two function yourself.
Code:
'Date Created: 30-Jan-2007 07:43:01 PM 'Last Updated: 30-Jan-2007 08:20:19 PM 'Created By : Marcel Kollenaar 'Updated By : Marcel Kollenaar 'Purpose: Read and write keys from and to INI file with a bunch of Monkeys (API). 'Create a 1k string buffer for holding the returned. declarestruct sReturnedString C1024value 'Access API function. DECLARE kernel32 GetPrivateProfileString@GetPrivateProfileStringA LCCC(sReturnedString)LC ' |||| | || 'Returnvalue------------------------------------------------------+||| | || 'SectionName-------------------------------------------------------+|| | || 'KeyName------------------------------------------------------------+| | || 'Default-------------------------------------------------------------+ | || 'ReturnedString---------------------------------------------------------------+ || 'Size----------------------------------------------------------------------------------+| 'FileName-------------------------------------------------------------------------------+ DECLARE kernel32 WritePrivateProfileSection@WritePrivateProfileStringA LCCCC ' ||||| 'Returnvalue-----------------------------------------------------------+|||| 'SectionName------------------------------------------------------------+||| 'KeyName-----------------------------------------------------------------+|| 'String-------------------------------------------------------------------+| 'FileName------------------------------------------------------------------+ dim sRetStr as {sReturnedString} dim result as N result := GetPrivateProfileString("sectie","naam","Not Present",sRetStr,1024,"test.ini") msgbox("�NFO",sRetStr.value +": " +str(len(sRetStr.value))) result := WritePrivateProfileSection("section","number","79","test.ini") 'Look for the result in the ini file.
A simple INI file is provided here.