Hoy traemos un codigo implementado por un colega de elhacker.net, el cual es sencillo pero util para verificar la existencia de archivos x en un x lugar.
El ejemplo utiliza 4 archivos de texto en la misma ubicacion que su proyecto/ejecutable, 4 labels, 4 timers y 4 botones de comando.
La idea del proyecto es que al presionar en cada boton, ejecute una funcion - o instruccion - que verifique la veracidad de existencia de un archivo (en este caso un txt) y lo muestre en un label a modo de informacion.
Option Explicit
Private Sub Timer1_Timer()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(App.Path & "/" & "documento1.txt") = True Then
Label1.BackColor = &HFF0000
Else
Label1.BackColor = &HFF&
End If
End Sub
Private Sub Timer2_Timer()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(App.Path & "/" & "documento2.txt") = True Then
Label2.BackColor = &HFF0000
Else
Label2.BackColor = &HFF&
End If
End Sub
Private Sub Timer3_Timer()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(App.Path & "/" & "documento3.txt") = True Then
Label3.BackColor = &HFF0000
Else
Label3.BackColor = &HFF&
End If
End Sub
Private Sub Timer4_Timer()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(App.Path & "/" & "documento4.txt") = True Then
Label4.BackColor = &HFF0000
Else
Label4.BackColor = &HFF&
End If
End Sub
El codigo es sencillo y se puede aplicar a otras necesidades, gracias por compartirlo.
Saludos!
No hay comentarios:
Publicar un comentario