Visual Basic - CONTAR

Life is soft - evento anual de software empresarial
 
Vista:

CONTAR

Publicado por JULIOESCOBAR (98 intervenciones) el 27/01/2005 04:34:50
AMIGOS: TENGO UN ARCHIVO .TXT Y QUIERO QUE AL PRESIONAR UN BOTON ME DIGA CUANTOS REGISTROS SON,EL ARCHIVO ES SIN COMILLAS, EJEMPLO:
12345678923344
25666955544558
58999994555555

SON 3 REGISTROS Y DESPUES COMO, LOS PASO A UN DBGRID SEPARADOS POR POSICIONES, DE LA 1 A LA 5 QUE SEA UN CAMPO DE LA 6 A LA 9 OTRO, ETC. ??? GRACIAS
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:CONTAR

Publicado por Benjo (679 intervenciones) el 27/01/2005 04:54:44
Debés referenciar Microsoft Scripting Runtime desde el Menú Proyecto

Private Sub Command1_Click()
Dim fso, txtfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("c:\prueba.txt", True)
txtfile.WriteLine ("1111122222333")
txtfile.WriteLine ("4444455555666")
txtfile.WriteLine ("7777788888999")
txtfile.Close
End Sub
Private Sub Command2_Click()
Dim fso As New FileSystemObject, txtfile, _
fil1 As File, ts As TextStream
Set fil1 = fso.GetFile("c:\prueba.txt")
Set ts = fil1.OpenAsTextStream(ForReading)
s = ts.ReadAll
Dim valores
valores = Split(s, vbNewLine)
Debug.Print valores(0)
Debug.Print valores(1)
Debug.Print valores(2)
'Ahora desglosas
Debug.Print Mid(valores(0), 1, 5), Mid(valores(0), 6, 5), Mid(valores(0), 11, 3)
Debug.Print Mid(valores(1), 1, 5), Mid(valores(1), 6, 5), Mid(valores(1), 11, 3)
Debug.Print Mid(valores(2), 1, 5), Mid(valores(2), 6, 5), Mid(valores(2), 11, 3)
ts.Close
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar