Error BASE/1005 No existe la variable de instancia: NAME

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
edufloriv
Posts: 238
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Error BASE/1005 No existe la variable de instancia: NAME

Post by edufloriv »

Saludos amigos,

Hace bastante tiempo que me viene sucediendo este error, lo extraño es que sucede no constantemente sino eventualmente, es decir, a veces sucede y a veces no, y la verdad no logro dar con la razón por la cual ocurre.

Tengo esta función para pasar información de una dbf a excel:

Code: Select all

FUNC Dbf_A_Xls( cLaDbf , cTitulo , aTitulos , aCamposBase , aFormatos , aAlineacion , aColores , aTotaliza , nQueHoja )

LOCAL aTotal

   ***Solo en MS office XP
   IF nQueHoja = NIL
      oExcel := CreateObject( "Excel.Application" )  // HMG 3
      oWorkBook := oExcel:WorkBooks:Add()
      oHoja := oExcel:ActiveSheet
   ELSE
      IF nQueHoja = 1
         oExcel := CreateObject( "Excel.Application" )  // HMG 3
         oWorkBook := oExcel:WorkBooks:Add()
         oHoja := oExcel:ActiveSheet
      ELSE
         nSheets := oExcel:Sheets:Count()
         IF nSheets >= nQueHoja
            oExcel:Sheets(nQueHoja):Select()
         ELSE
            oExcel:Sheets:Add()
         ENDIF
         oHoja := oExcel:ActiveSheet
      ENDIF
   ENDIF

// Prepara el array para las columnas totalizadas.
   aTotal := ARRAY( LEN(aCamposBase) )
   AFILL( aTotal , 0 )

// Se setea el tipo y el tamaño de letra de las hojas
   oHoja:Cells:Font:Name := "Arial"
   oHoja:Cells:Font:Size := 8

// Formatear las columnas
   IF ! aFormatos = NIL

      FOR nCol = 1 TO LEN( aFormatos )

         oHoja:Columns( nCol ):NumberFormat := aFormatos[nCol]

      NEXT

   ENDIF

// Colorear las columnas
   IF ! aColores = NIL

      FOR nCol = 1 TO LEN( aColores )

         IF VALTYPE(aColores[nCol]) = 'A'
            oHoja:Columns( nCol ):Font:Color := RGB(aColores[nCol,1],aColores[nCol,2],aColores[nCol,3])
         ENDIF

      NEXT

   ENDIF

// Alinear las columnas
   IF ! aAlineacion = NIL

      FOR nCol = 1 TO LEN( aAlineacion )

         DO CASE
            CASE aAlineacion[nCol] = 'I'
               oHoja:Columns( nCol ):HorizontalAlignment := -4131
            CASE aAlineacion[nCol] = 'C'
               oHoja:Columns( nCol ):HorizontalAlignment := -4108
            CASE aAlineacion[nCol] = 'D'
               oHoja:Columns( nCol ):HorizontalAlignment := -4152
         ENDCASE

      NEXT

   ENDIF

// ........................................................
// Carga de los titulos de los campos
   nLin := 2
   FOR nCol := 1 to Len( aTitulos )
      oHoja:Cells( nLin, nCol ):VALUE := aTitulos[ nCol ]
   NEXT

// ........................................................
// Carga Valores de la Base en la Planilla
   SELE &cLaDbf
   GOTO TOP
   nRow := 3
   DO WHILE ! EOF()
      FOR nCol = 1 to Len( aCamposBase )
         cCampo := aCamposBase[ nCol ]
         vCampo := &cCampo
         IF VALTYPE( vCampo ) = 'C'
            vCampo := RTRIM(vCampo)
         ENDIF
         oHoja:Cells( nRow, nCol ):Value := vCampo
         IF ! aTotaliza = NIL
            IF aTotaliza[nCol] = .T.
               aTotal[nCol] := aTotal[nCol] + vCampo
            ENDIF
         ENDIF
      NEXT
      nRow++
      SKIP
   ENDDO
   cRango := "A3:"+XlsColName( LEN(aTitulos) , nRow )
   oHoja:Range( cRango ):Borders:LineStyle   := 1


// Totaliza las columnas
   IF ! aTotaliza = NIL
      FOR nCol = 1 to LEN( aCamposBase )
         IF aTotaliza[nCol] = .T.
            oHoja:Cells( nRow, nCol ):Value                 := aTotal[nCol]
            oHoja:Cells( nRow, nCol ):Font:Bold             := .T.
            oHoja:Cells( nRow, nCol ):Interior:Color        := RGB( 255 , 215 , 0 )
            oHoja:Cells( nRow, nCol ):Borders(7):LineStyle  := 1 // Left
            oHoja:Cells( nRow, nCol ):Borders(8):LineStyle  := 1 // Top
            oHoja:Cells( nRow, nCol ):Borders(9):LineStyle  := 1 // Bottom
            oHoja:Cells( nRow, nCol ):Borders(10):LineStyle := 1 // Right
         ENDIF
      NEXT
   ENDIF

// ........................................................
// Ajusta Anchos de Columnas
   FOR nCol:=1 TO Len( aCamposBase )
      oHoja:Columns( nCol ):AutoFit()
   NEXT

// ........................................................
// Formatea las titulos de los campos - se pone al final pq estan afectados
// por la alineacion de columnas hecha arriba y los titulos siempre serán centrados.
   cRango := CHR(64+1)+LTRIM(STR(nLIN))+":"+XlsColName(LEN(aTitulos),nLIN)
   oHoja:Range( cRango ):Font:Bold := .T.
   oHoja:Range( cRango ):Interior:ColorIndex := 36 //sombrear celdas
   oHoja:Range( cRango ):Borders:LineStyle   := 1  // grillado
   oHoja:Range( cRango ):HorizontalAlignment := -4108 // centrado

// ........................................................
// Escribe el encabezado del reporte en la primera fila
// Se coloca aca al final para que el AUTOFIT no se ajuste al ancho del titulo del reporte.
   oHoja:Cells( 1 , 2 ):VALUE := cTitulo
   oHoja:Cells( 1 , 2 ):HorizontalAlignment := -4131 // izquierda

// Congela las 2 primeras filas
   oHoja:Cells( 3 , 1 ):Select()
   oExcel:Application:ActiveWindow:FreezePanes := .T.

   IF nQueHoja = NIL
      oExcel:Visible := .T.
   ENDIF

RETURN NIL
La llamada la realizo así:

Code: Select all

   Win_Ventas.Statusbar.Item (1) := 'Generando reporte en excel...'
   cXlsTitu := 'Productos estancados al '+DTOC(DATE())
   aXlsTits := {'CODIGO'   , 'PRODUCTO' , 'LABO'     , 'Stock'   , 'Ult.Mov.'   ,'Comp.Fecha' , 'Dias'      , 'Existencia'  , 'Comp.Unids.' }
   aXlsCams := {'COD_ARTI' , 'DES_ARTI' , 'COD_MARK' , 'STOCK'   , 'ULTIMO'     ,'COMFEC'     , 'COMDIA'    , 'COMSTK'      , 'COMUNI'      }
   aXlsForm := {'@'        , '@'        , '@'        , '#'       , '@'          ,'@'          , '#'         , '#'           , '#'           }
   aXlsAlin := {'C'        , 'I'        , 'I'        , 'C'       , 'C'          ,'C'          , 'C'         , 'C'           , 'C'           }
   aXlsColo := {nil        , nil        , nil        , {128,0,0} , nil          ,{75,0,130}   , {255,0,0}   , {255,20,147}  , {75,0,130}    }
   aXlsTota := {.F.        , .F.        , .F.        , .F.       , .F.          , .F.         , .F.         , .F.           , .F.           }

   Dbf_A_Xls( 'XLOG' , cXlsTitu , aXlsTits , aXlsCams , aXlsForm , aXlsAlin , aXlsColo , aXlsTota )

   CLOSE XLOG
   Win_Ventas.Statusbar.Item (1) := '...'
La mayoría de las veces funciona sin problema alguno, y pasa que en ciertas ocasiones, sin aparente razón, me lanza el siguiente error:
Error BASE/1005 No existe la variable de instancia: NAME

Called from _NAME(0)
Called from DBF_A_XLS(43)
Called from REPO_ESTANCADOS(101)
Called from (b)REGISTRODEVENTAS(212)
Called from _DOCONTROLEVENTPROCEDURE(6056)
Called from EVENTS(1756)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5717)
Called from REGISTRODEVENTAS(663)
Called from ABREMODULO(242)
Called from EJECUTAOPCION(225)
Called from (b)MAIN(102)
Called from _DOCONTROLEVENTPROCEDURE(6056)
Called from EVENTS(1816)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5717)
Called from MAIN(173)
Quisiera saber si hay forma de evitarlo. Agradezco su atención y tiempo.

Cordiales saludos

Eduardo Flores Rivas


LIMA - PERU
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Error BASE/1005 No existe la variable de instancia: NAME

Post by franco »

I am having the same problem in a couple of different areas. I am thinking the program has not finished updating before moving on.
It seems to happen more with very quick users ????????
Franco
All The Best,
Franco
Canada
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Error BASE/1005 No existe la variable de instancia: NAME

Post by andyglezl »

* No tendrás algo invalido en tu arreglo aFormatos ?
*
// Formatear las columnas
IF ! aFormatos = NIL

FOR nCol = 1 TO LEN( aFormatos )

oHoja:Columns( nCol ):NumberFormat := aFormatos[nCol]

NEXT

ENDIF ************* Linea 43
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
edufloriv
Posts: 238
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Re: Error BASE/1005 No existe la variable de instancia: NAME

Post by edufloriv »

Hola Andy,

Lo que menciona Franco es correcto, parece suceder con lo que yo llamo "usuarios ansiosos", pero incluso me ha pasado a mi. Noté que si cambio el enfoque a otra ventana durante el proceso aumentan las posibilidades de que salga el error.

Con respecto a los parametros no creo que sea eso, porque como te mencioné en el post, es la misma procedure, solo que en ocasiones me lanza el error y en otras funciona perfectamente (felizmente son más las veces que funciona bien).

Agradezco su tiempo y atención.


Cordiales saludos,


Hello Andy,

What Franco mentions is correct, it seems to happen with what I call "anxious users", but it has even happened to me. I noticed that changing the focus to another window during the process increases the chances of the error coming out.

With respect to the parameters I do not think that is that, because as I mentioned in the post, it is the same procedure, only that sometimes it throws me the error and in others it works perfectly (happily they are more the times it works well).

I appreciate your time and attention.


Greetings,

Eduardo Flores Rivas


LIMA - PERU
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Error BASE/1005 No existe la variable de instancia: NAME

Post by SALINETAS24 »

Hola Edu, creo que tienes que evitar tener la ventana activa. Y lo tengo solucionado con

Wait Window "Trabajando para usted, Espere . . ." NOWait

Y ademas puedes poner varios a lo largo del proceso para que el "usuario ansioso" vea que realmente está trabajando.
Y para terminar lo hacer un son "Wait Clear"

.. Quedaría algo así

Code: Select all

FUNC Dbf_A_Xls( cLaDbf , cTitulo , aTitulos , aCamposBase , aFormatos , aAlineacion , aColores , aTotaliza , nQueHoja )

LOCAL aTotal
Wait Window "Trabajando para usted, Espere . . ." NOWait  // --> Incia el proceso
   ***Solo en MS office XP
   IF nQueHoja = NIL
      oExcel := CreateObject( "Excel.Application" )  // HMG 3
      oWorkBook := oExcel:WorkBooks:Add()
      oHoja := oExcel:ActiveSheet
   ELSE
      IF nQueHoja = 1
         oExcel := CreateObject( "Excel.Application" )  // HMG 3
         oWorkBook := oExcel:WorkBooks:Add()
         oHoja := oExcel:ActiveSheet
      ELSE
         nSheets := oExcel:Sheets:Count()
         IF nSheets >= nQueHoja
            oExcel:Sheets(nQueHoja):Select()
         ELSE
            oExcel:Sheets:Add()
         ENDIF
         oHoja := oExcel:ActiveSheet
      ENDIF
   ENDIF

// Prepara el array para las columnas totalizadas.
   aTotal := ARRAY( LEN(aCamposBase) )
   AFILL( aTotal , 0 )

// Se setea el tipo y el tamaño de letra de las hojas
   oHoja:Cells:Font:Name := "Arial"
   oHoja:Cells:Font:Size := 8

// Formatear las columnas
   IF ! aFormatos = NIL



      FOR nCol = 1 TO LEN( aFormatos )
      Wait Window "Formateando "+str(nCol)+"Espere . . ." NOWait  // --> Para relajar al "ansioso"	

         oHoja:Columns( nCol ):NumberFormat := aFormatos[nCol]

      NEXT

   ENDIF

// Colorear las columnas
   IF ! aColores = NIL

      FOR nCol = 1 TO LEN( aColores )
      
         Wait Window "Pintando Columna "+str(nCol)+"Espere . . ." NOWait  // --> Para relajar al "ansioso"

         IF VALTYPE(aColores[nCol]) = 'A'
            oHoja:Columns( nCol ):Font:Color := RGB(aColores[nCol,1],aColores[nCol,2],aColores[nCol,3])
         ENDIF

      NEXT

   ENDIF

// Alinear las columnas
   IF ! aAlineacion = NIL

      FOR nCol = 1 TO LEN( aAlineacion )


         DO CASE
            CASE aAlineacion[nCol] = 'I'
               oHoja:Columns( nCol ):HorizontalAlignment := -4131
            CASE aAlineacion[nCol] = 'C'
               oHoja:Columns( nCol ):HorizontalAlignment := -4108
            CASE aAlineacion[nCol] = 'D'
               oHoja:Columns( nCol ):HorizontalAlignment := -4152
         ENDCASE

      NEXT

   ENDIF

// ........................................................
// Carga de los titulos de los campos
   nLin := 2
   FOR nCol := 1 to Len( aTitulos )
      oHoja:Cells( nLin, nCol ):VALUE := aTitulos[ nCol ]
   NEXT

// ........................................................
// Carga Valores de la Base en la Planilla
   SELE &cLaDbf
   GOTO TOP
   nRow := 3
   DO WHILE ! EOF()
   	 //--------------------------------------------------------------
         //--> y aqui ya pones el registro que está pasando
         Wait Window "Cargando valor +"+aCamposBase[1]+"Espere . . ." NOWait  // --> Para relajar al "ansioso"
         // -----------------------------------------------------------
      FOR nCol = 1 to Len( aCamposBase )
         cCampo := aCamposBase[ nCol ]
         vCampo := &cCampo
         IF VALTYPE( vCampo ) = 'C'
            vCampo := RTRIM(vCampo)
         ENDIF
         oHoja:Cells( nRow, nCol ):Value := vCampo
         IF ! aTotaliza = NIL
            IF aTotaliza[nCol] = .T.
               aTotal[nCol] := aTotal[nCol] + vCampo
            ENDIF
         ENDIF
      NEXT
      nRow++
      SKIP
   ENDDO
   cRango := "A3:"+XlsColName( LEN(aTitulos) , nRow )
   oHoja:Range( cRango ):Borders:LineStyle   := 1


// Totaliza las columnas
   IF ! aTotaliza = NIL
      FOR nCol = 1 to LEN( aCamposBase )
         IF aTotaliza[nCol] = .T.
            oHoja:Cells( nRow, nCol ):Value                 := aTotal[nCol]
            oHoja:Cells( nRow, nCol ):Font:Bold             := .T.
            oHoja:Cells( nRow, nCol ):Interior:Color        := RGB( 255 , 215 , 0 )
            oHoja:Cells( nRow, nCol ):Borders(7):LineStyle  := 1 // Left
            oHoja:Cells( nRow, nCol ):Borders(8):LineStyle  := 1 // Top
            oHoja:Cells( nRow, nCol ):Borders(9):LineStyle  := 1 // Bottom
            oHoja:Cells( nRow, nCol ):Borders(10):LineStyle := 1 // Right
         ENDIF
      NEXT
   ENDIF

// ........................................................
// Ajusta Anchos de Columnas
   FOR nCol:=1 TO Len( aCamposBase )
      oHoja:Columns( nCol ):AutoFit()
   NEXT

// ........................................................
// Formatea las titulos de los campos - se pone al final pq estan afectados
// por la alineacion de columnas hecha arriba y los titulos siempre serán centrados.
   cRango := CHR(64+1)+LTRIM(STR(nLIN))+":"+XlsColName(LEN(aTitulos),nLIN)
   oHoja:Range( cRango ):Font:Bold := .T.
   oHoja:Range( cRango ):Interior:ColorIndex := 36 //sombrear celdas
   oHoja:Range( cRango ):Borders:LineStyle   := 1  // grillado
   oHoja:Range( cRango ):HorizontalAlignment := -4108 // centrado

// ........................................................
// Escribe el encabezado del reporte en la primera fila
// Se coloca aca al final para que el AUTOFIT no se ajuste al ancho del titulo del reporte.
   oHoja:Cells( 1 , 2 ):VALUE := cTitulo
   oHoja:Cells( 1 , 2 ):HorizontalAlignment := -4131 // izquierda

// Congela las 2 primeras filas
   oHoja:Cells( 3 , 1 ):Select()
   oExcel:Application:ActiveWindow:FreezePanes := .T.

   IF nQueHoja = NIL
      oExcel:Visible := .T.
   ENDIF
   
Wait Clear  // --> TERMINA EL PROCESO
RETURN NIL
Es la única forma que se me ocurre para el usuario no haga el "tonto" con el ratón. jajajaja
Ah, también puede utilizar una PROGRESBAR .., pero es más trabajoso.., más bonito pero más trabajoso.
Venga.. una cervecita fresquita.
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
edufloriv
Posts: 238
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Re: Error BASE/1005 No existe la variable de instancia: NAME

Post by edufloriv »

Hola Salinetas,

Agradezco tu tiempo, probaré tu solución. :D

Cordiales saludos amigo.

Eduardo Flores Rivas


LIMA - PERU
edk
Posts: 914
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Error BASE/1005 No existe la variable de instancia: NAME

Post by edk »

Maybe try to call DO EVENTS in each DO WHILE and FOR ... NEXT loops to flush the MESSAGE LOOP buffer.

Is the line number 43 in the sources is:
oHoja:Cells:Font:Name:="Arial" ?
Maybe for some reason the oHoja object takes a value that is not an active sheet object?
Post Reply