Page 1 of 1

Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 12:20 pm
by Mario Mansilla
Hola :
alguien ha experimentado problemas con la funcion Ole2TxtError() con la nueva version de Harbour .
Tengo una aplicacion donde evaluo la instalacion de Excel y aunque este instalado la funcion no devuelve "S_OK" como antes .
Probe con Try Cath como alternativa pero en Harbour da error .

Hi:
someone has experienced problems with Ole2TxtError() function with the new version of Harbour.
I have an application where Excel will assess the installation and installed but this function does not return "S_OK" as before.
Try Probe with Cath as an alternative but fails in Harbour

Hmg 3.0
//////
oExcel := CreateObject("Excel.Application")

If Ole2TxtError() != "S_OK" <-- Error
MsgStop("Excel no esta disponible" )
Return nil
Endif
////////

Saludos
Mario Mansilla

Re: Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 12:42 pm
by mol
Maybe try to test returned value:

xAnswer := Ole2TxtError()
MsgBox("The type of answer is: " + valtype(xAnswer))

Maybe little sample?

(I'm using export to excel in my project, but I'm using BEGIN SEQUENCE... RECOVER
to catch errors)

Re: Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 1:31 pm
by Mario Mansilla
Hola Mol
He probado lo que me propusiste y me devuelve un caracter nulo (nil) , ascii (cero) .

Tienes un ejemplo de uso de BEGIN SEQUENCE .. RECOVER para capturar errores .

Saludos .
Mario Mansilla

Hello Mol
I tried what I set out and returns me a null character (nil), ascii (zero).

You have an example of use of BEGIN SEQUENCE .. RECOVER to catch errors.

Greetings.
Mario Mansilla

Re: Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 1:45 pm
by mol

Code: Select all

	
        XLSfile := "sample.xls"
	OldErrorDriver  := ErrorBlock({|e| break(e)})
	BEGIN SEQUENCE
		
		oExcel := CreateObject( "Excel.Application")
		oExcel:Workbooks:Open(XLSfile, 2, .f., 1, "", "", .f.)

		if oExcel:ActiveWorkBook:ReadOnly
			MsgInfo("XLS file cannot be open in WRITE mode!")
			lSheetOK := .f.
			oExcel:Quit()
			// remove excel from memory
			oExcel := NIL
		else
                        // I need to turn off autocalculation in Excel to speed writing to sheet
			xlCalcStatus := oExcel:Calculation
			oExcel:Calculation := xlManual
		endif
		
	RECOVER 
		MsgInfo("error while opening " + XLSfile)
		lSheetOK := .f.
	END
It's really working!

Re: Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 1:47 pm
by mol
Remember to restore error handle after

Code: Select all

   ErrorBlock(OldErrorDriver)

Re: Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 1:55 pm
by mol
You can read topic:
viewtopic.php?f=9&t=147

Re: Dbf To Excel ( Ole2TxtError() )

Posted: Tue Oct 27, 2009 1:58 pm
by Mario Mansilla
Gracias Mol
Thanks Mol

Greetings.
Mario Mansilla