Page 11 of 16
Re: HMG 3.1.1
Posted: Tue Feb 12, 2013 10:20 pm
by CarlosRD
hi all, again with a question.
searching and investigating folders in 3.0.46 version, i found AUTOFILL sample and it has been very usefull to me. comes to me the idea to save new entries (which are not in "countries.lst") in the moment, without the user noticing. can someone help me?
hola a todos y nuevamente con una pregunta.
navegando por los folders de la version 3.0.46, encontre el ejemplo de AUTOFILL en el folder "hmg\hfcl\samples\autofill" y ha sido de gran utilidad para mi. se pueden grabar las nuevas entradas que no existen en el archivo "countries.lst" en el momento de la edicion sin que el usuario se de cuenta?
de antemano, gracias por su ayuda.
Re: HMG 3.1.1
Posted: Tue Feb 12, 2013 10:33 pm
by esgici
Hola Carlos
CarlosRD wrote:searching and investigating folders in 3.0.46 version, i found AUTOFILL sample and it has been very usefull to me. comes to me the idea to save new entries (which are not in "countries.lst") in the moment, without the user noticing. can someone help me?.
Please look at
here.
I hope it give an idea
Salodus
Re: HMG 3.1.1
Posted: Tue Feb 12, 2013 10:33 pm
by danielmaximiliano
dentro de la misma carpeta HCFL se encuentra el archivo que necesitas
C:\hmg.3.1.1\hfcl\Samples\ComboSearchBox\countries.lst

- TextCrawler_2013-02-12_19-31-42.jpg (82.62 KiB) Viewed 8164 times
Re: HMG 3.1.1
Posted: Tue Feb 12, 2013 11:13 pm
by CarlosRD
esgici wrote:Hola Carlos
CarlosRD wrote:searching and investigating folders in 3.0.46 version, i found AUTOFILL sample and it has been very usefull to me. comes to me the idea to save new entries (which are not in "countries.lst") in the moment, without the user noticing. can someone help me?.
Please look at
here.
I hope it give an idea
Salodus
maybe I did not explain well.
my aplication works with tires models and marks, see that in "tires.lst" i have "Goodyear and Hankook". If in a new entry i type "Continental", the file "tires.lst" get a moditication and now it has "Goodyear, Hankook and Continental". That is what i want, could you help me?
Re: HMG 3.1.1
Posted: Wed Feb 13, 2013 6:36 pm
by CarlosRD
daniel, buenas tardes:
tengo algunos problemas con el manejo de array. he buscado en todos lo ejemplos y no encuentro como grabar los datos de un array en un archivo texto. puedes ayudarme?
estoy tratando de implementar en mi aplicacion el AUTOFILL, ya logre adicionar nuevos valores direfentes al array con el procedimiento abajo mencionado, pero ahora quiero grabar el array modificado en el mismo archivo de texto.
ejemplo:
para adicionar datos a un arreglo, se que es el aadd()
para ordenarlo, el asort()
para grabarlo nuevamente, ????????
te agrego el codigo que implemente y ojala pudieras ayudarme. gracias
onenter add_data() esta es una nueva instruccion al textbox
procedure add_data()
i=1
encontrado=.f.
newdata=frmAFTest.txbCountry.value
do while i<len(acountries)+1
datain:=acountries
if datain = newdata
encontrado=.t.
endif
i++
enddo
if !encontrado
aadd ( acountries,newdata )
endif
return
danielmaximiliano wrote:dentro de la misma carpeta HCFL se encuentra el archivo que necesitas
C:\hmg.3.1.1\hfcl\Samples\ComboSearchBox\countries.lst
[attachment=0]TextCrawler_2013-02-12_19-31-42.jpg[/attachment]
Re: HMG 3.1.1
Posted: Wed Feb 13, 2013 8:38 pm
by CarlosRD
bingo.... resuelto
utilice un dbf, del cual obtengo mi array y listo. gracias daniel de todas formas. gracias esgici por la molestia.
CarlosRD wrote:daniel, buenas tardes:
tengo algunos problemas con el manejo de array. he buscado en todos lo ejemplos y no encuentro como grabar los datos de un array en un archivo texto. puedes ayudarme?
estoy tratando de implementar en mi aplicacion el AUTOFILL, ya logre adicionar nuevos valores direfentes al array con el procedimiento abajo mencionado, pero ahora quiero grabar el array modificado en el mismo archivo de texto.
ejemplo:
para adicionar datos a un arreglo, se que es el aadd()
para ordenarlo, el asort()
para grabarlo nuevamente, ????????
te agrego el codigo que implemente y ojala pudieras ayudarme. gracias
onenter add_data() esta es una nueva instruccion al textbox
procedure add_data()
i=1
encontrado=.f.
newdata=frmAFTest.txbCountry.value
do while i<len(acountries)+1
datain:=acountries
if datain = newdata
encontrado=.t.
endif
i++
enddo
if !encontrado
aadd ( acountries,newdata )
endif
return
danielmaximiliano wrote:dentro de la misma carpeta HCFL se encuentra el archivo que necesitas
C:\hmg.3.1.1\hfcl\Samples\ComboSearchBox\countries.lst
[attachment=0]TextCrawler_2013-02-12_19-31-42.jpg[/attachment]
Re: HMG 3.1.1
Posted: Wed Feb 13, 2013 8:44 pm
by danielmaximiliano
CarlosRD wrote:daniel, buenas tardes:
tengo algunos problemas con el manejo de array. he buscado en todos lo ejemplos y no encuentro como grabar los datos de un array en un archivo texto. puedes ayudarme?
Carlos : para crear un archivo de texto necesitas utilizar primero
Code: Select all
FCREATE(<cFile>, [<nAttribute>]) --> nHandle
Arguments
<cFile> is the name of the file to create. If the file already
exists, its length is truncated to zero without warning.
<nAttribute> is one of the binary file attributes shown in the table
below. If this argument is omitted, the default value is zero.
Binary File Attributes
------------------------------------------------------------------------
Value Fileio.ch Attribute Description
------------------------------------------------------------------------
0 FC_NORMAL Normal Create normal read/write file (default)
1 FC_READONLY Read-only Create read-only file
2 FC_HIDDEN Hidden Create hidden file
4 FC_SYSTEM System Create system file
------------------------------------------------------------------------
nOutfile := FCREATE("Newfile.txt", FC_NORMAL)
te devuelve Handler o manejador, despues con Fwrite escribes el archivo
Code: Select all
FWRITE()
Write to an open binary file
------------------------------------------------------------------------------
Syntax
FWRITE(<nHandle>, <cBuffer>, [<nBytes>])
--> nBytesWritten
Arguments
<nHandle> is the file handle obtained from FOPEN(), FCREATE(), or
predefined by DOS.
<cBuffer> is the character string to write to the specified file.
<nBytes> indicates the number of bytes to write beginning at the
current file pointer position. If omitted, the entire content of
<cBuffer> is written.
nOutfile := FCREATE("Newfile.txt", FC_NORMAL)
IF FWRITE(nOutfile, cBuffer ) > 0
? "Write Ok"
ELSE
? "Write fail"
ENDIF
FCLOSE(nOutfile)
espero te sirva
Re: HMG 3.1.1
Posted: Thu Feb 14, 2013 11:40 pm
by Leopoldo Blancas
Hola Carlos y DanielMaximiliano y todos los del Foro!!!
Aquí tengo una rutina que me ayuda mucho al Grabar Arrays a Ficheros y recuperarlos...
Espero que sea de su utilidad....
/ * * *
* SAVE_ARR.CH *
* Fichero de cabecera para grabar/restaurar arrays
*
*/
// En las siguientes macros fh es un handle de fichero
// Escribir elemento carácter:
// C<5 dígitos de longitudxvalor del carácter>
#define SAVE_CHAR(fh, cv) ;
FWrite(fh, "C" + Str(Len(cv), 5) + cv)
// Escribir elemento fecha: D<cadena de fecha>
#define SAVE_DATE(fh, dv) FWrite(fh, "D" + Dtoc(dv))
// Escribir elemento lógico: L<carácter T or F>
#define SAVE_LOG(fh, lv);
FWrite(fh, "L" + Iif(lv, "T", "F"))
// Escribir elemento numérico:
// N<longitud de 2 dígitos>
// <número formateado como una cadena>
#define SAVE_NUM(fh, nv) ;
FWrite(fh, "N" + Str(Len(Str(nv)),2) + ;
Str(nv))
// Escribir cabecera del array:
// A<longitud del array de 4 dígitos>
#define WRITE_AHD(fh, av) FWrite(fh, "A" + Str(Len(av), 4))
// Leer un tipo
#define GET_TYPE(fh) FReadStr(fh, 1)
// Leer tamaño del array
#define GET_AR_SIZE(fh) Val(FReadStr(fh, 4))
// Leer un elemento carácter
#define GET_CHAR(fh) FReadStr(fh, Val(FReadStr(fh, 5)))
// Leer un elemento de fecha
#define GET_DATE(fh) Ctod(FReadStr(fh, 8))
// Leer un elemento lógico
#define GET_LOG(fh) FReadStr(fh, 1) == "T"
// Leer un elemento numérico
#define GET_NUM(fh) Val(FReadStr(fh, Val(FReadStr(fh, 2))))
/ * * *
* SAVE_ARR.PRG *
* Fichero de programa que contiene las funciones SaveArray()
* y RestArray() para grabar y restaurar arrays a / desde
* disco
*/
#include "Save_arr.ch"
I * * *
* SaveArray(aArray, cFileName) *
* aArray[] - -Array a grabar
* cFileName - -Fichero en el que se grabará el array
*/
FUNCTION SaveArray(aArray, cFileName)
LOCAL fHandle := FCreate(cFileName)
SaveArr(fHandle, aArray)
FClose(fHandle)
RETURN NIL
STATIC FUNCTION SaveArr(fHandle, aArray)
LOCAL LenArray, ElemType, i
// Escribir la cabecera del array WRITE_AHD(fHandle, aArray) LenArray := Len(aArray)
// Escribir cada elemento en el array
FOR i := 1 TO LenArray
ElemType := ValType(aArray)
DO CASE
CASE ElemType == "A"
//A subarray, recurse ~EL
SaveArr(fHandle, aArray)
CASE ElemType == "B"
// Error fatal - no podemos escribir los code blocks ? "ERROR: NO SE PUEDE GRABAR UN CODE BLOCK
InKey(0)
CASE ElemType == "C"
// Grabar un elemento de tipo carácter SAVE_CHAR(fHandle, aArray)
CASE ElemType == "D"
// Grabar un elemento de tipo fecha SAVE_DATE(fHandle, aArray)
CASE ElemType == "L"
// Grabar un elemento de tipo lógico SAVE_LOG(fHandle, aArray)
CASE ElemType == "N"
// grabar un elemento de tipo numérico
SAVE_NUM(fHandle, aArray)
ENDCASE
NEXT
RETURN NIL
/ * * *
* RestArray(cFileName) *
* cFileName - -Fichero desde el que se recuperará el array
*/
FUNCTION RestArray(cFileName)
LOCAL aRestArr, fHandle := FOpen(cFileName)
GET_TYPE(fHandle)
aRestArr := RestArr(fHandle)
FClose(fHandle)
RETURN aRestArr
FUNCTION RestArr(fHandle)
LOCAL LenArray, i, ElemType, aArray
// Determinar el tamaño del array
LenArray := GET_AR_SIZE(fHandle)
aArray := Array(LenArray)
// Restaurar cada elemento
FOR i := 1 TO LenArray
// Determinar su tipo
ElemType := GET_TYPE(fHandle)
DO CASE
CASE ElemType == "A"
// Si se trata de otro array usamos recursividad
aArray := RestArr(fHandle)
CASE ElemType == "B"
// Error fatal - No se grabó
CASE ElemType == "C"
aArray := GET_CHAR(fHandle)
CASE ElemType == “D”
aArray := GET_DATE(fHandle)
CASE ElemType == “L”
aArray := GET_LOG(fHandle)
CASE ElemType == “N”
aArray[i] := GET_NUM(fHandle)
ENDCASE
NEXT
RETURN aArray
/*************************************************************************
*Tenemos que hacer dos ficheros con la información arriba descrita
*1.- Save_arr.ch // que va a ser un archivo de cabecera y
*2.- SAVE_ARR.PRG // que va a tener las funciones para grabar y restaurar arrays a disco.
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
*Y con solo poner en tu código:
#include <hmg.ch>
#include "Fileio.ch"
#include "Dbstruct.ch"
#include "SAVE_ARR.CH "
SaveArray(aMiArray,GuardaMiArray.txt) //Graba en el disco el fichero que contiene la información del array.
*y con:
aMiArray := RestArray(GuardaMiArray.txt) //Carga el array con los valores que guardo mi archivo *.txt
#include "SAVE_ARR.PRG "
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Espero que haya sido claro.
Saludos
Polo
Re: HMG 3.1.1
Posted: Thu Feb 14, 2013 11:45 pm
by Leopoldo Blancas
Hola...
Por ahi hay una "I" al inicio de una linea debe de ser "/"
Saludos
Polo
Re: HMG 3.1.1
Posted: Fri Feb 15, 2013 12:54 am
by esgici
Thanks to sharing Polo
Saludos