|
-
Jun 29th, 2000, 01:15 PM
#1
Thread Starter
Hyperactive Member
How can I load up an .ini file from my program and set the current directory in view to the directory path listed in the .ini file?
-
Jun 29th, 2000, 01:48 PM
#2
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:
'read
'x = readini("test.ini", "test", "C:\test.ini")
'MsgBox X
'write
'Call writeini("test.ini", "test", "yes", "C:\test.ini")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How to read and write from/to an ini file
-
Jun 29th, 2000, 01:52 PM
#3
PowerPoster
Here some sample...
Code:
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
Private RetStr As String
Private dl As Long
Private DEFAULT_DRIVE As String
Private DEFAULT_PATH As String
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Form_Load()
'Assumption:
'1. You are refering to the DriveListBox, DirListBox control.
'2. An ini file with name Directory.ini under the application directory.
RetStr = String(255, Chr(0))
dl = GetPrivateProfileString("Directory", "Default", "C:", RetStr, Len(RetStr), App.Path & "\directory.ini")
If dl <> 0 Then
DEFAULT_PATH = Left(RetStr, InStr(1, RetStr, Chr(0), vbTextCompare) - 1)
DEFAULT_DRIVE = Mid(DEFAULT_PATH, 1, 2)
Drive1.Drive = DEFAULT_DRIVE
Dir1.Path = DEFAULT_PATH
End If
End Sub
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
|