Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

John B. or anyone else help with ini file

Status
Not open for further replies.

nina1

Programmer
Aug 14, 2001
31
CA
My data acces from VB is hardcoded to mdb.file, so after instaling app. to another mashine, it look for mdb. file
John B suggested ini. file to point app. to database.
I don't know how to do that , if anyone can help me please , so I can keep my existing code.
Thanks.
 
Hi,

Use Jasek78 solution instead. Change the path of the database to a path relative to where the program is installed (of course the easiest is just to place it in the same directory (app.path).



Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
To get the information from an ini file you need to declare the following API functions:

Code:
Declare Function GetPrivateProfileSection Lib _
"kernel32" Alias "GetPrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

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

Then in your program you can use something like this:

Code:
Public Function gGetFromIni(ByVal strSectionHeader As String, ByVal strVariableName As String, ByVal strFileName As String) As String
'** requires declaration of GetPrivateProfileString in INImodule
On Error GoTo Err_Handler
    Dim strReturn As String
    ' Blank the return string
    strReturn = String(255, Chr(0))
    'Get requested information, trimming the returned string
    gGetFromIni = Left$(strReturn, GetPrivateProfileString(strSectionHeader, ByVal strVariableName, "", strReturn, Len(strReturn), strFileName))
    
Err_Exit:
    Exit Function
Err_Handler:
    MsgBox "Error retrieving from INI file"
    Resume Err_Exit
End Function

Call that section using code like this:

Code:
strINIPath = "C:\Program Files\Common Files\Symantec Shared\VirusDefs\Definfo.dat"     
DateString = gGetFromIni("DefDates", "CurDefs", strINIPath)

*This particular code retrieves the latest virus definitions date from Norton AniVirus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top