|
-
Mar 26th, 2000, 08:40 PM
#1
I'm trying to get the path to the db from an .ini file. Does anyone know how to parse the file until it finds 'Path='. I'm going to come up with a solution myself, if I come up with one before there's one posted I'll post it.
-
Mar 26th, 2000, 10:25 PM
#2
Lively Member
Put the code below in a standard module and if you have an ini file c:\myapp.ini defined as follows
[MyApp]
DBPath=whatever_the path_is
use the follwog code to get the setting
dim sPath as string
sPath = GetProfile("MyApp","DBPath","c:\myapp.ini")
----------------------------------------
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
Public Function GetProfile(ByVal sApplication As String, ByVal sKey As String, _
ByVal sIniFilename As String) As String
Dim sTemp As String * 255
Dim lRes As Long
lRes = GetPrivateProfileString(sApplication, sKey, "", sTemp, 255, sIniFilename)
GetProfile = Trim(sTemp)
End Function
-
Mar 28th, 2000, 08:06 PM
#3
New Member
Thanks for your help but I couldn't seem to get it going.
This does the trick though.
BAS Module Declarations section
public APP_DB as string
public INI_FILE as string
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
Function GetINIString(ByVal SECTION$, ByVal szItem$, ByVal szDefault$) As String
Dim tmp As String
Dim X As Integer
tmp = String$(2048, 32)
X = GetPrivateProfileString(SECTION$, szItem$, szDefault$, tmp, Len(tmp), INI_FILE)
GetINIString = Mid$(tmp, 1, X)
End Function
****************** Put in Form_Load
INI_FILE = "C:\blah.ini" '
APP_DB = GetINIString("Database", "Path", App.Path)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|