Berikut ini adalah fungsi untuk membaca dan menulis ke dalam File .ini dengan menggunakan bahasa pemrograman Visual Basic 6.

Option Explicit

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 Declare Function GetPrivateProfileString Lib "Kernel32" Alias _
    "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
    lpKeyName As Any, ByVal lpdefault As String, ByVal lpreturnedstring As Any, _
    ByVal nsize As Long, ByVal lpfilename As String) As Long

Public Function ReadValue(Key As String, Optional Default As String, 
    Optional Section As String, Optional File)
    ' Read from INI file
    Dim sReturn As String
    If IsMissing(File) Then File = FullPath(App.Path, "\config\config.ini")
    sReturn = String(255, Chr(0))
    ReadValue = Left(sReturn, GetPrivateProfileString(Section, Key, Default, sReturn, Len(sReturn), File))
    'ReadValue("CSound02", sValue, "CSOUND")
End Function

Public Sub SaveValue(Key As String, Value As String, 
    Optional Section As String = "WonderHTML", Optional File)
    ' Write to INI file
    If IsMissing(File) Then File = FullPath(App.Path, "\config\config.ini")
    WritePrivateProfileString Section, Key, Value, File
End Sub

Function FullPath(lpPath As String, lpFile As String) As String
    If Right(lpPath, 1) <> "\" Then lpPath = lpPath & "\"
    FullPath = lpPath & lpFile
    'fullpath, after resolving the "\" problems
End Function

Public Function CBinary(Expression As Boolean) As Integer
    'Useful for converting BOOLs to 0 or 1. CByte() would
    'return 255 for true, which wont be useful for setting the
    'values of, for instance, a checkbox; as it uses 0 and 1.
    If Expression = False Then CBinary = 0 Else CBinary = 1
End Function

Cara pemanggilan
//Baca File Ini --> ReadValue(SaveValue Key, Value, Section)

//Tulis File Ini --> SaveValue(Key, Value, Section)

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s