Results 1 to 3 of 3

Thread: inininininininininininininininini

  1. #1

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    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?

  2. #2
    Guest
    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


  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    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
  •  



Click Here to Expand Forum to Full Width