Results 1 to 4 of 4

Thread: Using .ini files

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Using .ini files

    This is gonna sound dumb (no change there then) but it's something I've never done before so please be patient!

    All I want to do is store a database path and a string variable (eg: strlettercode = "SL42") in an .ini file so I can alter it whenever I need to.

    I'm guessing it's simple but then again, so am I!

    Cheers
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    This will show you how to do it.sorry no vb on this pc.

    The Writeprofile code will save your data to the file.
    The Getprofile retreives it from the file to say a texbox for you to either alter or just view it.


    VB Code:
    1. 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
    2. Private 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
    3. Private Sub Form_Load()
    4.     'KPD-Team 1999
    5.     'URL: [url]http://www.allapi.net/[/url]
    6.     'E-Mail: [email][email protected][/email]
    7.     Dim Ret As String, NC As Long
    8.     'Write the setting to the file (c:\test.ini) under
    9.     '   Project1 -> Keyname
    10.     WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
    11.     'Create a buffer
    12.     Ret = String(255, 0)
    13.     'Retrieve the string
    14.     NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    15.     'NC is the number of characters copied to the buffer
    16.     If NC <> 0 Then Ret = Left$(Ret, NC)
    17.     'Show our string
    18.     MsgBox Ret
    19.     'Delete the file
    20.     Kill "c:\test.ini"
    21. End

  3. #3

  4. #4
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    1. Open notepad and create a file called value.ini
    2.Save your project and the value.ini file to same directory
    3.Add a textbox to your form and 2 x command buttons and when you add any value to the textbox it will save it in the inifile.
    4. You will be able to open the file with command2 and view it
    5. Copy code to form

    Hope this is what you require

    VB Code:
    1. 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
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    3. Const SW_SHOWMAXIMIZED = 3
    4. Private 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
    5.  
    6. Private Sub Command1_Click()
    7.  
    8. Dim Ret As String, NC As Long
    9.     'Write the setting to the file (c:\test.ini) under
    10.     '   Project1 -> Keyname
    11.     WritePrivateProfileString "HEADING", "strlettercode", Text1.Text, App.Path & "\VALUE.INI"
    12.     'Create a buffer
    13.    
    14. End Sub
    15.  
    16. Private Sub Command2_Click()
    17.  
    18.  
    19.    
    20.     ShellExecute Me.hwnd, vbNullString, "C:\VALUE.INI", vbNullString, "C:\", SW_SHOWMAXIMIZED

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