Writing .ini Files/How to Assign Keys
Ok i need some help trying to store some information for a "save game" but I Dont know how to write to a .ini or cfg file
Can you show me how to write and read a ini or cfg file
and can you also show me how to assign a keyboard Key such as A to do a certain function like attack or something
1 Attachment(s)
Re: Writing .ini Files/How to Assign Keys
Here's an INI sample.
As far as assigning keys, you'd use the keypress or keydown function to get the character, then process it however you want.
Re: Writing .ini Files/How to Assign Keys
You'll want to work with the following functions
Code:
'profile (INI file) subs & functions
Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long '_32_BIT_CONVERTED_'
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long '_32_BIT_CONVERTED_'
Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Long, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long '_32_BIT_CONVERTED_'
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long '_32_BIT_CONVERTED_'
Declare Function ErasePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Long, ByVal lpFileName As String) As Long '_32_BIT_CONVERTED_'
Declare Function ErasePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Long, ByVal lpString As Long, ByVal lpFileName As String) As Long '_32_BIT_CONVERTED_'
You can use those API functions to read from and write to ini files. By default it reads to and writes from the registry but you can use it to map to your own ini file. I can't remember off the top of my head how to do it, though. Sorry, it's been a while!
Re: Writing .ini Files/How to Assign Keys
@David: Nice little tutorial. :)
What always inrigued me: does anybody know how these functions work, with respect to the .ini file?
I mean that:
If I write a new key to a section of an existing file, is the file completely rewritten then? Must-of somehow, I think, because it's a sequential text file.
And if I read entries from the file I might read them in any unpredictable order, so: is the file then scanned (opened read and closed) for any entry I read?
Sorry. Just curiousity. :D