You are on page 1of 2

Option Explicit Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePri vateProfileStringA" (ByVal lpApplicationName As String, ByVal

lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivatePro fileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal n Default As Long, ByVal lpFileName As String) As Long Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivate ProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVa l lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, By Val lpFileName As String) As Long Public conn As ADODB.Connection Public rs2 As ADODB.Recordset Public user_login_id As String Public user_name As String ' pembacaan string pada ini file Public Sub writestring(Section As String, Key As String, Value As String, File A s String) WritePrivateProfileString Section, Key, Value, File End Sub ' membuat integer dari ini file Public Function ReadNumber(Section As String, Key As String, filename As String) As Long ReadNumber = GetPrivateProfileInt(Section, Key, 0, filename) End Function ' Function untuk pembacaaan dan pengulangan string dari ini file Public Function ReadString(Section As String, Key As String, filename As String) As String Dim s As String s = String(255, vbNullChar) GetPrivateProfileString Section, Key, "", s, Len(s), filename s = Left(s, InStr(s, vbNullChar) - 1) ReadString = s End Function 'untuk melakukan koneksi ke database Sub Koneksi() On Error GoTo err: Dim filename As String Dim Server, Uid, Psw, Db As String filename = "C:\Documents and Settings\root\My Documents\Project VB\koneksi.ini" Server = ReadString("DATA", "SERVER", filename) Uid = ReadString("DATA", "Uid", filename) Psw = ReadString("DATA", "Password", filename) Db = ReadString("DATA", "DB", filename) Set conn = New ADODB.Connection conn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};" _ & "SERVER=" + Server + ";" _ & " DATABASE=" + Db + ";" _ & "UID=" + Uid + ";PWD=" + Psw + "; OPTION=1 + 2 + 3 + 8 + 32 + 2048 + 16384;"

conn.Open Exit Sub err: MsgBox " Error Saat Melakukan koneksi" + Chr(13) + "Error Message: " + err.Descr iption, vbCritical, "Koneksi" End Sub 'menututp koneksi Public Sub Tutup_Kon() conn.Close Set conn = Nothing End Sub

You might also like