Sunday, 20 May 2012

Membuat Settingan dalam bentuk File sendiri

Sourcecode ini digunakan biasanya untuk menyimpan setingan-setingan yang telah diseting sebelumnya dan disimpan dalam bentuk file sepert *.dat dan lain-lain. Fungsi ini juga bisa digunakan untuk anda, misalkan ingin menyimpan settingan Jaringan, nama server,port , nama database, dll.

Langkah-langkahnya :
1. Buat 1 Form dan 1 Module.
2. Tambahkan 1 TextBox, 1 CommandButton


Masukan Kode Berikut

Kode untuk module :

Public 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
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

Function GetINI(strMain As String, strSub As String, sFileName As String) As String
  Dim strBuffer As String
  Dim lngLen As Long
  Dim lngRet As Long
 
  strBuffer = Space(100)
  lngLen = Len(strBuffer)
  lngRet = GetPrivateProfileString(strMain, strSub, vbNullString, strBuffer, lngLen, App.Path & "\" & sFileName)
  GetINI = Left(strBuffer, lngRet)
End Function

Public Sub SetINI(strMain As String, strSub As String, strvalue As String, sFileName As String)
  WritePrivateProfileString strMain, strSub, strvalue, App.Path & "\" & sFileName
End Sub

Kode untuk Form :
Private Sub Form_Load()
    Text1 = GetINI("Koneksi", "srv", "save.dat")      'get path from file
    If Trim(Text1) = "" Or IsNull(Text1) Then
JumpHere1:
        Text1 = ""                           'browse database
    End If
End Sub
 Private Sub Command1_Click()
SetINI "Koneksi", "srv", "localhost", "save.dat"
End Sub

ads

Kategori:

0 comments:

Post a Comment

Jika anda ingin berkomentar dan tidak mempunyai akun silahkan pilih anonymous.

Note: only a member of this blog may post a comment.

 
Masukan alamat Email kamu disini untuk mendapatkan artikel terbaru..!






Site Meter