-
Ok, try to stay with me... ;)
I want to load INI files into a Text Box, but how can I make it so when I write the INI's Path it will be in a different directory than my exe? For example... C:\MyApp\Files\MyFile.ini
I want to know this because when the user installs the exe, I don't know where they are ganna install the app. I remember seeing this somewhare and it was about one line code...
Thnaks!
-Emo
-
<?>
you want it all in the appPath
Dim AppPath$
If Right(App.Path, 1) <> "\" Then
AppPath = App.Path & "\"
Else
AppPath = App.Path
End If
save your file to AppPath & filename.ext
-
Here is how to read and write an INI:
Code:
Public 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
Public 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
Public Function readini(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let readini$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Public Sub writeini(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
Usage:
Call writeini("MyINI.ini", "Directory", "" & App.Path & "", "C:\MyINI.ini")
Text1.text = readini("MyINI.ini", "Directory", "C:\MyINI.ini")