Versi 1
Private Function OpenTextFile() As String
Dim nFileNum As Integer, sText As String Dim sNextLine As String, lLineCount As Long nFileNum = FreeFile Open "C:\daftar_driver.txt" For Input As nFileNum lLineCount = 1 Do While Not EOF(nFileNum) Line Input #nFileNum, sNextLine MsgBox sNextLine 'ini akan membaca file text baris per baris sNextLine = sNextLine & vbCrLf sText = sText & sNextLine Loop OpenTextFile = sText Close nFileNum End Function
Versi 2
1. Menulis Ke File TextDim LocTextFile As String LocTextFile = “C:\windows\SvAdd.txt” Open LocTextFile For Output As #1 ‘Buka file text Print #1, “Server_Name” ‘Modify Baris Pertama” Print #1, “Database_Name” ‘Modify Baris Kedua Print #1, “User” ‘Modify Baris Ketiga Print #1, “Pwd” ‘Modify Baris Keempat Close #12. Membaca dari File TextVersi 3Dim LocTextFile As String Dim ServerAddress As String Dim DatabaseName As String Dim UserID As String Dim PwdSql As String LocTextFile = “C:\windows\SvAdd.txt” Open LocTextFile For Input As #1 ‘Buka file text Line Input #1, ServerAddress ‘Baca Baris Pertama Line Input #1, DatabaseName ‘Baca Baris Kedua Line Input #1, UserID ‘Baca Baris Ketiga Line Input #1, PwdSql ‘Baca Baris Keempat Close #1 ‘Tutup File file text
Ini Fungsinya
Function ReadTextFileContents(filename As String) As String Dim fnum As Integer, isOpen As Boolean On Error GoTo Error_Handler fnum = FreeFile() Open filename For Input As #fnum isOpen = True ReadTextFileContents = Input(LOF(fnum), fnum) Error_Handler: If isOpen Then Close #fnum If Err Then Err.Raise Err.Number, , Err.Description End Function
Ini Cara Pakainya
TxtPesan.Text = ReadTextFileContents(App.Path & "\service.log")
Tidak ada komentar:
Posting Komentar