|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Import lines from an ini file
Hi
I want to import certain lines of data from an ini text file and insert it into a form text box eg Entry in ini file is "ArchiveDir=c:\archive". How can I search this file and insert "c:\archive" in thetext box txtArchive on a form? If the user also amends the directory using the text box - how dow you write it back to the ini file on closing ? Any help from a realatively new VBA programmer would be much appreciated. Thanks, Mat. |
|
#2
|
|||
|
|||
|
I use the following
Add to Module Code:
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 Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long Add textbox and command button to form, and add the below code to form. Code:
Function ReadINI(Section, KeyName, filename As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
Function writeini(sSection As String, sKeyName As String, sNewString As String, sFileName) As Integer
Dim r
r = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)
End Function
Private Sub Command1_Click()
Text1 = ReadINI("section1", "beeoch", App.Path & "\set.ini")
End Sub
Your ini file should be formated like the follwoing example. Code:
[section1] Place=junk beeoch=return-one poo=crap [section2] beeoch=return-two bog=lop Sam Land Dynamic DNS Server Suites |
|
#3
|
|||
|
|||
|
Write to ini file
Sam,
Brilliant ! Thanks for that simple but very useful advice. I now would like to be able to modify what is in the text box and write that back to the ini file. Could you help with some pointers for that? Your help is much appreciated from this relatively newbie at VBA. Mat. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Import lines from an ini file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|