Showing posts with label INI-File. Show all posts
Showing posts with label INI-File. Show all posts

Saturday, June 9, 2012

Menghapus Section Pada INI File

Option Explicit

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 Sub DeleteKey(Section As String, Key As String, PathIni As String)
Dim sSection As String
Dim sKey As String
Dim sFileName As String
sSection = Section
sKey = Key
sFileName = PathIni
If Len(Trim(sKey)) <> 0 Then
WritePrivateProfileString sSection, sKey, vbNullString, sFileName
Else
WritePrivateProfileString sSection, sKey, vbNullString, sFileName
End If
End Sub
READ MORE - Menghapus Section Pada INI File

Friday, June 8, 2012

VB6 Code - Fungsi Untuk Baca Tulis File .INI

Mengenai fungsi untuk baca tulis file .INI menggunakan VB6 Code - Adapun prosedure VB6 untuk baca tulis file .INI adalah sebagai berikut:
Option Explicit 

Private Declare Function
WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Declare Function
GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
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
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

Public Function
ReadIni(ByVal strSection As String, ByVal strKey As String, ByVal strDefault As String, ByVal strFileName As String) As String
Dim
intRes As Integer, strRet As String
strRet = Space$(32400)
intRes = GetPrivateProfileString(strSection, strKey, strDefault, strRet, Len(strRet), strFileName)
ReadIni = Left$(strRet, intRes)
End Function

Public Sub
WriteIni(ByVal strSection As String, ByVal strKey As String, ByVal strSetting As Variant, ByVal strFileName As String)
WritePrivateProfileString strSection, strKey, CStr(strSetting), strFileName
End Sub

Public Function
ReadWinIni(strSection As String, strKey As String) As String
Dim
Result As String * 128
Dim Temp As Integer
Temp = GetProfileString(strSection, strKey, "", Result, Len(Result))
ReadWinIni = Left$(Result, Temp)
End Function

Public Sub
WriteWinIni(strSection As String, strKey As String, strSetting As String)
WriteProfileString strSection, strKey, strSetting
End Sub
Contoh penggunaan kode di atas:
Private Sub Command1_Click() 
If Combo1.ListIndex < 0 Then
MsgBox "You must select the combo first!"
Exit Sub
End If
WriteIni "EXE", "EXE", Combo1.ListIndex, App.Path & "\windows.ini"
MsgBox "Run Again and look the change!"
Unload Me
End Sub

Private Sub
Form_Load()
Me.WindowState = ReadIni("EXE", "EXE", 0, App.Path & "\windows.ini")
With Combo1
.AddItem "Normal"
.AddItem "Minimized"
.AddItem "Maximized"
End With
End Sub
READ MORE - VB6 Code - Fungsi Untuk Baca Tulis File .INI

Sunday, April 4, 2010

VB6 Code - Baca Tulis INI File

Di bawah ini merupakan fungsi untuk baca tulis file .INI. menggunakan Visual Basic 6:
Option Explicit

Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
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
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

Public Function ReadIni(ByVal strSection As String, ByVal strKey As String, ByVal strDefault As String, ByVal strFileName As String) As String
Dim intRes As Integer, strRet As String
strRet = Space$(32400)
intRes = GetPrivateProfileString(strSection, strKey, strDefault, strRet, Len(strRet), strFileName)
ReadIni = Left$(strRet, intRes)
End Function

Public Sub WriteIni(ByVal strSection As String, ByVal strKey As String, ByVal strSetting As Variant, ByVal strFileName As String)
WritePrivateProfileString strSection, strKey, CStr(strSetting), strFileName
End Sub

Public Function ReadWinIni(strSection As String, strKey As String) As String
Dim Result As String * 128
Dim Temp As Integer
Temp = GetProfileString(strSection, strKey, "", Result, Len(Result))
ReadWinIni = Left$(Result, Temp)
End Function

Public Sub WriteWinIni(strSection As String, strKey As String, strSetting As String)
WriteProfileString strSection, strKey, strSetting
End Sub


READ MORE - VB6 Code - Baca Tulis INI File

Friday, March 19, 2010

VB6 Code - Cara Membuat Form Pada Saat Design Time

Artikel di bawah ini menjelaskan bagaimana cara membuat form pada saat design time melalui pengkodean Visual Basic 6.0. Langkah-langkah pembuatan: Buat project Add-Ins yang berasal dari template Secara default maka akan terdapat frmAddIn, di dalamnya terdapat kode:
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Option Explicit

Private Sub CancelButton_Click()
Connect.Hide
End Sub

Private Sub OKButton_Click()
MsgBox "AddIn operation on: " & VBInstance.FullName
End Sub

Public VBInstance As VBIDE.VBE
Public Connect As Connect

Gantilah seluruh kodenya dengan kode di bawah ini:

Option Explicit

Private Sub CancelButton_Click()
Connect.Hide
End Sub

Private Sub OKButton_Click()
Dim frm As VBIDE.VBComponent
Set frm = VBInstance.ActiveVBProject.VBComponents.Add(vbext_ct_VBForm)
With frm
.Properties("Name") = "frmMain"
.Properties("Width") = 7155
.Properties("Caption") = "Main Form"
.Properties("Height") = 5000
End With
End Sub

Langkah selanjutnya adalah meng-compile kodenya sehingga terbentuk file dengan nama "MyAddIn.dll".

Langkah-langkah menjalankan:

  1. Buka project baru
  2. Klik menu Add-Ins
  3. Klik Sub Menu My AddIn
READ MORE - VB6 Code - Cara Membuat Form Pada Saat Design Time

Thursday, March 18, 2010

VB6 Code - Cara Membuat Object Pada Saat Design Time

Artikel ini menjelaskan cara membuat object pada saat design time, tentu saja mudah, tetapi bukan cara membuat yang seperti "itu" yang dimaksud, ini melalui pengkodean (coding). Objek yang kita buat adalah CommandButton, bagaimana dengan objek lainnya? Anda qiyaskan saja dengan cara mengganti "CommandButton" dengan nama objek yang Anda kehendaki misalnya "TextBox" dan sebagainya. Adapun langkah-langkah membuat object pada saat design time:

  • Buat project Add-Ins yang terdapat pada template
  • Hapus seluruh kode yang terdapat pada frmAddIn
  • Gantikan dengan kode di bawah ini:
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Option Explicit

Private Sub CancelButton_Click()
Connect.Hide
End Sub

Private Sub OKButton_Click()
Dim frm As VBForm
Dim ctl As VBControl
Dim i As Integer

On Error GoTo ErrHandler

Set frm = VBInstance.SelectedVBComponent.Designer
For i = 1 To 255
Set ctl = frm.VBControls.Add("CommandButton")
Next
Set frm = Nothing
Set ctl = Nothing
Exit Sub

ErrHandler:

MsgBox Err.Description

End Sub

  • Compile kodenya dengan nama "MyAddIn.dll" (secara otomatis VB6.0 akan meregister file tersebut).
  • Tutup Project setelah Anda menyimpannya
  • Buka Project baru
  • Klik menu Add-Ins, maka disana akan terdapat sub menu yang bernama "My AddIn".
  • Selanjutnya klik Sub menu "My AddIn" maka akan terbentuklah objek CommandButton dengan jumlah 254, mengapa 254 tidak 255 seperti yang terdapat dalam kode?

Apa yang bisa kita petik dari kode-kode di atas, tentu saja banyak.
READ MORE - VB6 Code - Cara Membuat Object Pada Saat Design Time