APPEND FROM + Progress Bar

Post Reply
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

APPEND FROM + Progress Bar

Post by George »

Seria posible utilizar un control "progress bar" durante un APPEND FROM?
Alguna sugerencia o codigo de alguien que lo haya implementado?

Gracias

George
User avatar
Patricio Avalos Aguirre
Posts: 1060
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile
Contact:

Re: APPEND FROM + Progress Bar

Post by Patricio Avalos Aguirre »

Hola

Yo utilizo con un MsgRun..


Code: Select all | Expand

    MsgRun( "Espere, importando ", "Usuario",;
                             { || __dbApp( cPath + "\"+cDbf, {},,,,,.F., "DBFCDX") } )


podrias hacerlo dentro del codeblock :-)
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
ronaldo
Posts: 139
Joined: Fri Nov 25, 2005 4:38 pm
Location: brasil
Contact:

Re: APPEND FROM + Progress Bar

Post by ronaldo »

Eu, utilizo desta forma:


APPEND FROM IMOVEL ;
FOR If(lNewFile,(oMtr1:nTotal:=Reccount(), Sysrefresh(), lNewFile:=.f.,.t. ), (nPercent1++,oMtr1:Set(nPercent1),SysRefresh(),.t. ) )
Ronaldo Minacapelli
Sistemas, Hospedagem e Criação de WebSites
http://www.bazevani.com.br
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: APPEND FROM + Progress Bar

Post by George »

Gracias Ronaldo y Patricio por su ayuda.
Creo cualquiera de las dos soluciones propuesta por ustedes me sirve.

Saludos

George
antolin
Posts: 498
Joined: Thu May 10, 2007 8:30 pm
Location: Sevilla

Re: APPEND FROM + Progress Bar

Post by antolin »

Ronaldo,

Está muy ben. ¿Se podría utilizar un CodeBlock o llamara una funcción desde la clausula FOR?

Gracias
Peaaaaaso de foro...
FWH 2007 - xHarbour - BCC55
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: APPEND FROM + Progress Bar

Post by George »

Añadiendo un dialogo NOWAIT con el control METER, el siguiente codigo funciona:

Code: Select all | Expand


     MsgRun(cMsgRun, "Creating Transactions file January 2010 [BETA 0.9]",;
             { || TransaJan2010() })

FUNCTION TransaJan2010()
    APPEND FROM "Jan2010.CSV" FOR  (nPercent1++, oMtr1:Set(nPercent1),  SysRefresh()  )  DELIMITED WITH (,)
RETURN (.T.)
 


El problema es que hice una prueba añadiendo cerca de 800,000 records con los siguientes resultados:
A) Sin el METER tarda 1.5 minutos
B) Con el METER tarda casi 7 minutos.

Habra algun otro modo de hacerlo o alguna otra sugerencia?

Saludos


George
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: APPEND FROM + Progress Bar

Post by Daniel Garcia-Gil »

George..


Pueds intentar hacer el SysRefresh() cada "x" registros, por ejemplo 100, 200, 500 o 1000
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: APPEND FROM + Progress Bar

Post by George »

Gracias Daniel por tu sugerencia.
Con el siguiente cambio en APPEND FROM se toma ahora cerca de 2 minutos lo cual es aceptable.

Code: Select all | Expand


FUNCTION TransaJan2010(nPercent1, oMtr1)
    APPEND FROM "Jan2010.CSV" WHILE (nPercent1++, oMtr1:Set(nPercent1),  IIF( (nPercent1/1000 - int(nPercent1/1000)) = 0 , SysRefresh(), ), TRUE  )  DELIMITED WITH (,)
RETURN (.T.)
 


George
Enrrique Vertiz
Posts: 549
Joined: Fri Oct 07, 2005 2:17 pm
Location: Lima - Peru
Contact:

Re: APPEND FROM + Progress Bar

Post by Enrrique Vertiz »

Buen dia

Alguien tiene el ejemplo completo de como funciona un APPEND FROM con el PROGRESS BAR, trato de implementar el que aqui adjuntan pero no me sale bien, GRACIAS
Enrrique Vertiz Pitta
Lima-Peru
xHb 1.23.1026X, Fwh 24.09, BCC74, MySQL 8.0.X, SQLLIB 1.9m
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: APPEND FROM + Progress Bar

Post by George »

Enrique aqui tienes un ejemplo de la implementación de la barra de progreso leyendo el CSV que está en el array.

Code: Select all | Expand


#include "FIVEWIN.CH"

FUNCTION Main()
    LOCAL oDlg, oMeter, nActual := 0
    DEFINE BRUSH oBrush COLOR CLR_LGRAY
        DEFINE WINDOW oDlg ;
            TITLE "Reading CSV file in array";
            BRUSH oBrush;
            FROM 0,0 TO 20, 80

         @ 8, 10 METER oMeter VAR nActual TOTAL 100 OF oDlg SIZE 500, 30

    ACTIVATE WINDOW oDlg ON INIT ( oDlg:Center(), ReadCSV(oDlg, oMeter))


FUNCTION ReadCSV(oDlg, oMeter) 
    LOCAL cMsgRun := "Procedure in execution; please Wait...", cMsgArrayData := "Creating CSV array data; please wait..."
    LOCAL nStart := Seconds(), nEnd, aData := {}, cText := "", cMsgMemo := "Reading CSV data source; please wait..."

    //===================================================================================================================
    // STEP ONE: Read CSV File
    //===================================================================================================================
    cFileCSV = "your_file.csv"
    MsgRun(cMsgMemo, "Main",  { | | cText := fCSVMemo(cFileCSV) })
    Sysrefresh()

    //===================================================================================================================
    // STEP TWO:  Read each line and save the result in array aData
    //===================================================================================================================
    MsgRun(cMsgArrayData, "Main",  { | | aData := HB_ATokens( cText, Chr(1), .t., .t. ) })
    syswait(.05)
    Sysrefresh()

    ? "Total rows in array: ", len(aData), " ", "Delay (secs): ", (Seconds() - nStart)

    separate_fields_in_array(aData, oDlg, oMeter)


FUNCTION fCSVMemo(cFileCSV)
    cText := StrTran( MemoRead( cFileCSV ), CRLF, Chr(1) )
RETURN (cText)

FUNCTION separate_fields_in_array(aData, oDlg, oMeter)

    //=======================================================================================================================
    // STEP THREE: Separate fields in each line based in delimiters and save the info in Array
    //=======================================================================================================================
    nLenData := int(len(aData))
    nDivisor := int(nLenData/100)
    IIF( nDivisor < 1, nDivisor := 1,)
    oMeter:nTotal := nLenData
    oMeter:Set(0)

    AEval( aData, { |c,i| c := StrTran( c, Chr(1), CRLF ), aData[ i ] := HB_ATokens( c, ",", .t., .t. ), MyProgressBar(i, nDivisor, oMeter, oDlg) } )
    nSec4 := Second()
    oMeter:Set(nLenData)
    syswait(.05)
    Sysrefresh()


//================================================================================================================
FUNCTION MyProgressBar(i, nDivisor, oMeter, oDlg)
    IIF(i/nDivisor = int(i/nDivisor),;
        (oMeter:Set(i),sysrefresh()),)
RETURN (.T.)


 
Enrrique Vertiz
Posts: 549
Joined: Fri Oct 07, 2005 2:17 pm
Location: Lima - Peru
Contact:

Re: APPEND FROM + Progress Bar

Post by Enrrique Vertiz »

George

GRACIAS eso era lo que necesitaba !!! y es rapidisimo en comparacion con leer Excel
Enrrique Vertiz Pitta
Lima-Peru
xHb 1.23.1026X, Fwh 24.09, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Post Reply