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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ini file location....

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I would like to create an ini file to store file location and destination... I would like to be able to pull these paths into the code in order to run the procedure (could it appear in a text box or label on the form from the ini?)...

I then need to use the location in the ini file to copy two known files (xtrain.mdb and user.mdb) and then send these copies to the destination... so...

FileCopy "txtlocation.text", "txtdestination.text"

Would this work... sound possible?

Thanks
 
First to make a INI-file you must write a few functions. Put them in a module

'API-DECLARATIES
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

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 sGetINI(sINIFile As String, sSection As _ String, sKey As String, sDefault As String) As String

Dim sTemp As String * 256
Dim nLength As Integer

sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, _ sDefault, sTemp, 255, sINIFile)
sGetINI = Left$(sTemp, nLength)

End Function

Public Sub writeINI(sINIFile As String, sSection As String, sKey As String, sValue As String)

Dim n As Integer
Dim sTemp As String

sTemp = sValue

'replace CR/LF by space
For n = 1 To Len(sValue)
If Mid$(sValue, n, 1) = vbCr Or Mid$(sValue, n, 1) _ = vbLf Then Mid$(sValue, n) = ""
Next n

n = WritePrivateProfileString(sSection, sKey, sTemp, sINIFile)
End Sub

Then you can write and read from a INI-File. But it is a lot easier to use the REGISTRY.

You write to the registry with the command GetSetting
and save with SaveSetting

You can find that back in the REGISTRY under
HKEY_CURRENT_USER\SOFTWARE\VB and VBA Program Settings

When you use filecopy, it is better to write the path also.
ex.
FileCopy App.path & "\verw.log", app.path "\archief.log"

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top