Private Sub BtnBibleVerseMsgBox2Okay_Click(sender As Object, e As EventArgs) Handles BtnBibleVerseMsgBox2Okay.Click
If ListBox1.SelectedIndex <> -1 Then
System.IO.File.Delete(ListBox1.Items(ListBox1.SelectedIndex).fullname())
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End If
End Sub
Please, I am intending to delete Listbox item i.e. delete selected item from both folder and Listbox using the above code. However, implementing the code, the file was deleted accordingly, but i got a conflicting error with a previous code, as given below, at line 13:
Dim files() As String
Dim Pause As Integer = 5
Dim pointer As Integer = 0
Dim folder As String = "ph1\" ' set to required folder
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
files = IO.Directory.GetFiles(folder, "*.txt")
Timer2.Enabled = True
End if
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Timer2.Interval = Pause * 1000
LblBibleVerses3.Text = IO.File.ReadAllText(files(pointer))
pointer += 1
If pointer > files.Count - 1 Then pointer = 0
End Sub
This terminated the application.
Solution Attempt:
I have attempted some solutions i.e. using the below code, added in Timer2_Tick event, but all to no avail, see below:
If LblBibleVerses3.Text Is Nothing Then
Return
End If
Please, see attachment to view the error page. Thank you.!
[1]: /answers/storage/attachments/197129-capture-20220427-111452new.png