Me gusta mas la forma Binaria xd por que asi puedo controlar a mi gusto el archivo.
Bueno, aparte de esto tambien parece mas rápida, por lo menos que Input(LOF) y Line InputBueno, aparte de esto Binary-Space(LOF) es mas rápido, por lo menos que Input(LOF) y Line Input
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Function ArrStr_vData(StrC_Dir As String) As String
Dim Int_FF%
'Dim ArrByt_vData() As Byte ' // Opcion 1
If Dir(StrC_Dir, vbArchive) <> "" Then ' // Existe el archivo?.
Int_FF% = FreeFile ' // Obtenemos un nuevo registro libre para su lectura.
Open StrC_Dir For Binary As Int_FF% ' // Me gusta mas la forma Binaria xd por que asi puedo controlar a mi gusto el archivo.
If LOF(Int_FF) > 0 Then
'ReDim ArrByt_vData(0 To LOF(Int_FF%) - 1) ' // Opcion 1
ArrStr_vData$ = Space(LOF(Int_FF%)) ' // Opcion 2
'Get Int_FF%, 1, ArrByt_vData ' // Opcion 1
Get Int_FF%, 1, ArrStr_vData$ ' // Opcion 2
End If
Close Int_FF% ' // Cerrar Registro
End If
End Function
Function Input_LOF(StrC_Dir As String) As String
If Dir(StrC_Dir, vbArchive) <> "" Then
Open StrC_Dir For Input As #1
If LOF(1) > 0 Then
Input_LOF = Input(LOF(1), #1)
End If
Close #1
End If
End Function
Function Line_Input(StrC_Dir As String) As String
Dim linea As String
If Dir(StrC_Dir, vbArchive) <> "" Then
Open StrC_Dir For Input As #1
If LOF(1) > 0 Then
While Not EOF(1)
Line Input #1, linea
Line_Input = Line_Input & linea & vbNewLine
Wend
End If
Close #1
End If
End Function
Private Sub Form_Load()
Dim t As Long
Dim x As Long
Open "C:\Archivot.txt" For Output As #1
For x = 1 To 150
Print #1, "LINEA" & vbTab & x
Next
Close #1
'---------------------------------------------------------------
t = GetTickCount
For x = 1 To 10000
Call ArrStr_vData("C:\Archivot.txt")
Next
t = GetTickCount - t
MsgBox ArrStr_vData("C:\Archivot.txt"), , "ArrStr_vData " & t
'---------------------------------------------------------------
t = GetTickCount
For x = 1 To 10000
Call Input_LOF("C:\Archivot.txt")
Next
t = GetTickCount - t
MsgBox Input_LOF("C:\Archivot.txt"), , "Input_LOF " & t
'---------------------------------------------------------------
t = GetTickCount
For x = 1 To 10000
Call Line_Input("C:\Archivot.txt")
Next
t = GetTickCount - t
MsgBox Line_Input("C:\Archivot.txt"), , "Line_Input " & t
'---------------------------------------------------------------
End Sub