Perbaikan kode pada buku “Membuat Virus dan Antivirus – Be Expert” tentang file hasil scan yang tidak bisa dihapus. Ternyata hal itu dikarenakan salah ambil nilai dari kolom listview hasil scan, berikut kode lama:
Private Sub DeleteAction()
On Error GoTo err:
Dim keRecycleBin As Boolean
keRecycleBin = False
Msg = MsgBox("Pilihlah metode penghapusan:" & vbCrLf & "Yes untuk penghapusan total" & vbCrLf & "No untuk hapus ke recycle bin" & vbCrLf & "Cancel jika tidak jadi menghapus", vbInformation + vbYesNoCancel, "SEngine")
If Msg = vbYes Then
keRecycleBin = False
ElseIf Msg = vbNo Then
keRecycleBin = True
Else
Exit Sub
End If
For i = 1 To lFound.ListItems.Count
If lFound.ListItems.Item(i).Checked = True Then
DoEvents
If delCancel = True Then
Exit For
End If
sFile = lFound.ListItems.Item(i).SubItems(2)
Debug.Print sFile
DeleteFileEx Me.hWnd, CStr(sFile), keRecycleBin, False
lFound.ListItems.Remove i
DoEvents
i = i - 1
End If
Next i
err:
MsgBox "Penghapusan selesai.", vbInformation, "SEngine"
End Sub
Berikut perbaikan kode:
Private Sub DeleteAction()
On Error GoTo err:
Dim keRecycleBin As Boolean
keRecycleBin = False
Msg = MsgBox("Pilihlah metode penghapusan:" & vbCrLf & "Yes untuk penghapusan total" & vbCrLf & "No untuk hapus ke recycle bin" & vbCrLf & "Cancel jika tidak jadi menghapus", vbInformation + vbYesNoCancel, "SEngine")
If Msg = vbYes Then
keRecycleBin = False
ElseIf Msg = vbNo Then
keRecycleBin = True
Else
Exit Sub
End If
For i = 1 To lFound.ListItems.Count
If lFound.ListItems.Item(i).Checked = True Then
DoEvents
If delCancel = True Then
Exit For
End If
sFile = lFound.ListItems.Item(i).SubItems(3)
Debug.Print sFile
DeleteFileEx Me.hWnd, CStr(sFile), keRecycleBin, False
lFound.ListItems.Remove i
DoEvents
i = i - 1
End If
Next i
err:
MsgBox "Penghapusan selesai.", vbInformation, "SEngine"
End Sub