Resumen Importar y exportar archivos txt   (2 mensajes )

Qué tal Marcelo,

Mirá, tengo este material sacado del suplemento "101 Tech Tips" de la revista VBPJ de febrero de este año. Creo que puede servirte...

VB3, VB4 16/32, VB5, VBA
Level: Intermediate

CONVERT A TEXT FILE INTO ACCESS MDB
It can be troublesome to convert a text file into an Access database. It takes a lot of time to open the file for
sequential access and create new records using the AddNew method. Instead, use the Text ISAM driver and
SQL to do the job for you. First, create a SCHEMA.INI file for the text file and place it in the same directory as
the text file. Use this code to convert the database:

Dim db As Database, tbl as TableDef
Set db = DBEngine.CreateDatabase(App.Path & _
        "\mymdb.mdb", dbLangGeneral, dbVersion_0)
Set tbl = db.CreateTableDef("Temp")
tbl.Connect = "Text;database=c:\vbpj\data"
tbl.SourceTableName = "Customer#txt"
db.TableDefs.Append tbl
db.Execute "Select Temp.* into NewTable from Temp"
db.TableDefs.Delete tbl.Name
db.Close
Set tbl = Nothing
Set db = Nothing

Now, you only need to create indexes. You can use this method to convert text files in excess of 100,000
records in a few seconds.

-Richard Mageau, Warren, Rhode Island



VB3, VB4 16/32, VB5, VBA
Level: Intermediate

QUICK AND EASY SCHEMA.INI
To create a SCHEMA.INI file for a text file quickly and easily, let the ODBC setup and drivers do it for you. Go to
the Control Panel and start ODBC. Click on the Add button and select the Text driver. Click on the Options
button and describe how to arrange the text file. If your text file has a header record, click on the Guess button,
and the ColumnNames will be filled out for you. On the last screen, choose Cancel to avoid setting up the data
source. Check the directory where the text file resides, and you'll find a new SCHEMA.INI file.

-Richard Mageau, Warren, Rhode Island


Bueno, espero que te sea útil, hasta pronto,

Leonardo Bosi
Buenos Aires, Argentina
leobosi@feedback.net.ar
leonardo@bosi.biocom.com
ICQ # 9027216
---------------------------------
"What do you want to reinstall today?"

function < fichero a base de datos>
   Data1.Recordset.Edit
   Call putmemo( "pepito.doc", Data1.Recordset, "documento")
   Data1.Recordset.Update
end function

function
         Call getmemo( "pepito.doc", Data1.Recordset, "documento")
end function

Function putmemo(cFile As String, oRc As Recordset, cCampo As String)
  Dim n As Integer
  Dim nCanal As Integer
  Dim cInter As String
  Dim nMax As Long
  Dim nLeer As Long

  nMax = FileLen(cFile)
  nCanal = FreeFile
  Open cFile For Binary Access Read As nCanal

  Do While nMax > 0
     nLeer = IIf(nMax > 50000, 50000, nMax)
     nMax = nMax - nLeer
     cInter = Space(nLeer)
     Get nCanal, , cInter
     oRc(cCampo).AppendChunk cInter
  Loop
  Close nCanal

End Function


Function getmemo(cFile As String, oRc As Recordset, cCampo As String)
  Dim nCanal As Integer
  Dim cInter As String
  Dim nMax As Long
  Dim nLeer As Long
  Dim n As Long
  If IsNull(oRc(cCampo)) Then
     nMax = 0
  Else
       nMax = Len("" & oRc(cCampo))
  End If

  n = 0
  nCanal = FreeFile
  Open cFile For Binary As nCanal
  Do While nMax > 0
     nLeer = IIf(nMax > 50000, 50000, nMax)
     nMax = nMax - nLeer
     cInter = oRc(cCampo).GetChunk(n, nLeer)
     n = n + Len(cInter)
     Put nCanal, , cInter
  Loop
  Close nCanal
End Function
  espero que te sea util
Hasta otra
Pablo Leon Gonzalez
pleong@meditex.es

-----Original Message-----
De: animagics@pinos.com <animagics@pinos.com>
Para: vb-esp@ccc.uba.ar <vb-esp@ccc.uba.ar>
Fecha: martes 12 de mayo de 1998 1:57
Asunto: (VB-ESP) ARCHIVO DE TEXTO EN BASE DE DATOS

> Hola a todos, tengo que ingresar datos a una base de datos
>proveniente de un archivo de texto(*.txt) y despues hacer lo contrario
>convertir algunos registro en archivo de texto. El que me pueda ayudar les
>doy las gracias...
>
>Marcelo F. Rodriguez
>E-mail: Animagics@pinos.com
>ICQ: 12255206
>
>



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com