Hello,
I have a text file with a name of domain and source of html, I would like to have a button
that can edit the data from the text file! what I have been using is a button (save as new) and then
clicking on (delete) is it possible to add an (edit) button to this code?
Option Explicit
Dim FSO As Object
Private Sub Form_Load()
Dim TS As Object
Dim i As Long
Dim sContent As String
Dim vRows, vCells
Set FSO = CreateObject("Scripting.Fi
leSystemOb
ject")
If Not FSO.FileExists(App.Path & "\names.txt") Then
Set TS = FSO.CreateTextFile(App.Pat
h & "\names.txt")
End If
Set TS = FSO.OpenTextFile(App.Path & "\names.txt")
If TS.AtEndOfLine Then
TS.Close
Set TS = Nothing
Exit Sub
End If
sContent = TS.ReadAll
TS.Close
vRows = Split(sContent, vbCrLf)
For i = 0 To UBound(vRows)
vCells = Split(vRows(i), "**!!**")
If UBound(vCells) >= 0 Then ListBox1.AddItem (vCells(0))
Next
If ListBox1.ListCount > 0 Then ListBox1.ListIndex = 0
End Sub
Public Sub ReloadINI()
ListBox1.Clear
Call Form_Load
End Sub
Private Sub ListBox1_Click()
Populate (ListBox1.ListIndex)
End Sub
Public Sub Populate(ByVal Record As Long)
Dim FileNo As Long
Dim strLine As String
FileNo = FreeFile()
Open App.Path & "\names.txt" For Input As #FileNo
Dim intRecord As Long
For intRecord = 0 To Record
If Not EOF(FileNo) Then
Line Input #FileNo, strLine
End If
Next
Close #FileNo
Dim values As Variant
values = Split(strLine, "**!!**")
If UBound(values) >= 1 Then
txtDomain = values(0)
txtSource = values(1)
End If
End Sub
Private Sub cmdDelete_Click()
Dim TS As Object
Dim sContent As String
Dim vRows
Dim i As Long
If ListBox1.ListIndex <> -1 Then
Set TS = FSO.OpenTextFile(App.Path & "\names.txt")
sContent = TS.ReadAll
TS.Close
vRows = Split(sContent, vbCrLf)
sContent = ""
For i = 0 To UBound(vRows)
If i <> ListBox1.ListIndex And vRows(i) <> "" Then sContent = sContent + vRows(i) + vbCrLf
Next
Set TS = FSO.OpenTextFile(App.Path & "\names.txt", 2)
TS.Write (sContent)
TS.Close
ListBox1.RemoveItem (ListBox1.ListIndex)
SetFocus
Call ReloadINI
End If
End Sub
Private Sub cmdSave_Click()
Dim FileNo As Integer
FileNo = FreeFile
Open App.Path & "\names.txt" For Append Shared As #FileNo
Print #FileNo, Replace(txtDomain.Text & "**!!**" & txtSource.Text, vbCrLf, " ")
Close #FileNo
SetFocus
Call ReloadINI
End Sub
Private Sub cmdEdit_Click()
'edit button needed
End Sub