Tuesday, 13 January 2015

Membaca Dan Merubah File ini atau txt pada vb6

Form menu utama



Berikut adalah cara atau membaca dan merubah data yang ada di file dot ini dengan vb6. silahkan buka notepad anda lalu simpan dengan extensi .ini

 berikut adalah codingan nya :

Pertama kita buat dahulu Function nya :
Taro ini di module

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Function WriteIni(KeySection As String, KeyKey As String, KeyValue As String) As Boolean
    Dim lngResult As Long, strFileName As String, AppPath As String
   
    ' Get the full path to the ini-file.
    AppPath = App.Path
    If Right(AppPath, 1) = "\" Then
        strFileName = AppPath & "Setup\setup.ini"
    Else
        strFileName = AppPath & "\Setup\setup.ini"
    End If

    ' Write to ini-file
    lngResult = WritePrivateProfileString(KeySection, KeyKey, KeyValue, strFileName)
   
    ' Check if the write was successful
    If lngResult = 0 Then
        ' If an error occured, return False.
        WriteIni = False
    Else
        ' Return True (Successful write).
        WriteIni = True
    End If
End Function

Public Function ReadIni(KeySection As String, KeyKey As String) As String
    Dim lngResult As Long
    Dim strFileName
    Dim strResult As String * 50
   
    ' Get the full path to the ini-file.
    AppPath = App.Path
    If Right(AppPath, 1) = "\" Then
        strFileName = AppPath & "Setup\setup.ini"
    Else
        strFileName = AppPath & "\Setup\setup.ini"
    End If
   
    ' Read the ini-file
    lngResult = GetPrivateProfileString(KeySection, KeyKey, strFileName, strResult, Len(strResult), strFileName)
   
    ' Check if the read was successful
    If lngResult = 0 Then
        ' If an error occured, return "error".
        ReadIni = "error"
    Else
        ' Return the value.
        ReadIni = Left(strResult, lngResult)
    End If
End Function

setelah itu kita masukan ke form utama







isi file setting nya

Private Sub Command1_Click()
Text1.Text = ReadIni("Setting", "Tinggi")
Text2.Text = ReadIni("Setting", "Panjang")
Text3.Text = ReadIni("Setting", "Lebar")

Text4.Text = ReadIni("Aplikasi", "Nama")
End Sub

Private Sub Command2_Click()
Text1.Text = WriteIni("Setting", "Tinggi", Text1.Text)
Text2.Text = WriteIni("Setting", "Panjang", Text2.Text)
Text3.Text = WriteIni("Setting", "Lebar", Text3.Text)

Text4.Text = WriteIni("Aplikasi", "Nama", Text4.Text)
Command1_Click
End Sub





kalo masih bingung silahkan download file nya
Download









Perhatian: Yuk Baca Artikel bagus di Nurul Musthofa

Artikel Terkait

No comments:

Post a Comment

 

Network

Pesan

Semoga situs ini bermanfaat