Matt_T_hat
Apr 8th, 2002, 05:55 PM
I have some code (below) from a tutorial. It's for an old fasioned INI file. I have been quite taken with it. In fact I have thought up a scripting technique for games!!
The problem is to be honest I don't really understand it suffieciently to modify it.
What I want to enclude is an additional key. So as opposed to Key/SubKey/Value I want MajorKey/MinorKey/SubKey/Value.
Can this be done. I'm assumeing so. I just don't know how.
Option Explicit
Private Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
' Functions
Function GetFromINI(sSection As String, sKey As String, sDefault_
As String, sIniFile As String)
Dim sBuffer As String, lRet As Long
' Fill String with 255 spaces
sBuffer = String$(255, 0)
' Call DLL
lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
If lRet = 0 Then
' DLL failed, save default
If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
GetFromINI = sDefault
Else
' DLL successful
' return string
GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
End If
End Function
' Returns True if successful. If section does not
' exist it creates it.
Function AddToINI(sSection As String, sKey As String, sValue As_
String, sIniFile As String) As Boolean
Dim lRet As Long
' Call DLL
lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
AddToINI = (lRet)
End Function
What I intend to do is define a standard "level" that is all the same all over. House type #1. Street type #1, walls at X,Y,Z.., etc. and then program by exeption!
What thinks you... ...wait no - how do i do it (add an extra Key-Level)?
That's better not half mile wide now
The problem is to be honest I don't really understand it suffieciently to modify it.
What I want to enclude is an additional key. So as opposed to Key/SubKey/Value I want MajorKey/MinorKey/SubKey/Value.
Can this be done. I'm assumeing so. I just don't know how.
Option Explicit
Private Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
' Functions
Function GetFromINI(sSection As String, sKey As String, sDefault_
As String, sIniFile As String)
Dim sBuffer As String, lRet As Long
' Fill String with 255 spaces
sBuffer = String$(255, 0)
' Call DLL
lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
If lRet = 0 Then
' DLL failed, save default
If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
GetFromINI = sDefault
Else
' DLL successful
' return string
GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
End If
End Function
' Returns True if successful. If section does not
' exist it creates it.
Function AddToINI(sSection As String, sKey As String, sValue As_
String, sIniFile As String) As Boolean
Dim lRet As Long
' Call DLL
lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
AddToINI = (lRet)
End Function
What I intend to do is define a standard "level" that is all the same all over. House type #1. Street type #1, walls at X,Y,Z.., etc. and then program by exeption!
What thinks you... ...wait no - how do i do it (add an extra Key-Level)?
That's better not half mile wide now