Texto en objetos de formulario a bloc de notas.

Aquí puedes preguntar o compartir tus dudas y conocimientos acerca del programa
Que tal gente, espero que esten muy bien:

Versión de AMS que actualmente uso: 8.0.7.0

Un proyecto que tengo en desarrollo cuenta con un formulario principal, el cual contiene inputs en la mayoría de objetos para insertar texto y solo un richtext. Gracias a dudas pude crear un código que pasara la información de un input a un bloc de notas con la posibilidad de guardarlo donde el usuario quisiera, aquí el código:
nc = Input.GetText("Input1");--Cabe señalar que la variable "nc" es "nombre de cliente".
if (nc ~= "")then
ncg =Dialog.FileBrowse(false,"Guardar orden de servicio", Shell.GetFolder(SHF_DESKTOP), "Texto (*.txt)|*.txt|", "Número de orden", ".txt", false, false);
if (ncg[1] ~= "CANCEL") and (nc ~= "") then
TextFile.WriteFromString(ncg[1], nc, false);
if (Application.GetLastError () == 0) then
Dialog.Message("Orden de servicio", "Creado correctamente", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
Dialog.Message("Orden de servicio", "Orden no guardada, intentelo nuevamente", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
end
end
else
Dialog.Message("Orden de servicio", "No hay datos que guardar", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
end
...pero no tengo idea de cómo hacer que lo que se escriba en los demás inputs y el richtext se guarde en el mismo archivo de texto, sin tanta pesca: Guardar todo lo que se escribe en el formulario en un solo archivo de texto. Gracias por su atención. :pc:

Saludos !!

Vamos por partes...

Para los formularios es mas sencillo utilizar ficheros .db o Bases de Datos, se me hace mucho lio meter los datos de formulario en un fichero de texto. Para esto, repito, son las Bases de Datos...

Ahora que si asi lo deseas en vez de utilizar la funcion TextFile.WriteFromString(); emplea la funcion TextFile.WriteFromTable();

Asumo que tienes dos Input dentro de tu proyecto y un boton:

Button On Click:
tbDataToSave = {};
sDato1 = Input.GetText("Input1");
sDato2 = Input.GetText("Input2");

if ((sDato1 ~= "") and (sDato2 ~= "")) then
	sDtS = Dialog.FileBrowse(false, "Guardar datos", Shell.GetFolder(SHF_DESKTOP), "Ficheros de Texto (*.txt)|*.txt|", "Cambiame", ".txt", false, false);
	if (sDtS[1] ~= "CANCEL") and (sDtS[1] ~= "") then
		tbDataToSave = {Nombre = sDato1, Apellido = sDato2};		
		for i, v in pairs(tbDataToSave) do
			TextFile.WriteFromTable(sDtS[1], tbDataToSave, false);
		end
	end
end
Comenta como te fue y de favor si logras lo que esperabas no te olvides de subir tu ejemplo para ayudar a otros usuarios.

Saludos ;)
Veré el ejemplo y reportaré como me fue, gracias ;)

metafunken usa la etiqueta LUA o en su defecto hightlingner para codigo.

Choca con el hide Rafa, entonces quito el hide?

Re:

Metafunken escribió:Choca con el hide Rafa, entonces quito el hide?
Yo el hide siempre lo he usado solo para enlaces de descarga

Lo he logrado, este código me funcionó:
tbDataToSave = {};
nc = Input.GetText("Input1");
tc = Input.GetText("Input2");
if ((nc ~= "") and (tc ~= "")) then
gdr = Dialog.FileBrowse(false, "Guardar cliente", Shell.GetFolder(SHF_DESKTOP), "Archivos de texto (*.txt)|*.txt|", "Número de cliente", ".txt", false, false);
if (gdr[1] ~= "CANCEL") and (gdr[1] ~= "") then
tbDataToSave = {Nombre = nc, Telefono_Celular = tc};
for i, v in pairs (tbDataToSave) do
TextFile.WriteFromTable(gdr[1], tbDataToSave, false);
if (Application.GetLastError () == 0) then
Dialog.Message ("Registro de clientes", "Creado correctamente.", MB_OK, MB_ICONINFORMATION, MB_DFBUTTON1);
else
Dialog.Message ("Registro de clientes", "Error al crear archivo, intentelo nuevamente.", MB_OK, MB_ICONSTOP, MB_DFBUTTON1);
end
end
end 
else
Dialog.Message ("Registro de clientes", "No hay archivos que guardar.", MB_OK, MB_ICONEXCLAMATION, MB_DFBUTTON1);
end
Y aquí el ejemplo :yes:

HIDE: ON
Hidebb Message Hidden Description


Saludos y muchas gracias !! :friends:

thanks

Solo para pulir detalles este es el código final personal:
tbDataToSave = {};
nc = Input.GetText("Input1");
tc = Input.GetText("Input2");
no = Input.GetText("Input9");
fch = Input.GetText("Input10");
re = Input.GetText("Input11");
ce = Input.GetText("Input4");
tl = Input.GetText("Input3");
mc = Input.GetText("Input6");
md = Input.GetText("Input5");
sn = Input.GetText("Input8");
os = Input.GetText("Input7");
sr = Input.GetText("Input12");
if ((nc ~= "") and (tc ~= "") and (no ~= "") and (fch ~= "") and (re ~= "") and (ce ~= "") and (tl ~= "") and (mc ~= "") and (md ~= "") and (sn ~= "") and (os ~= "") and (sr ~= ""))then
gdr = Dialog.FileBrowse(false, "Guardar orden", Shell.GetFolder(SHF_DESKTOP), "Archivos de texto (*.txt)|*.txt|", "Número de orden", ".txt", false, false);
if (gdr[1] ~= "CANCEL") and (gdr[1] ~= "") then
tbDataToSave = {Nombre = nc, Telefono_Celular = tc, Numero_de_orden = no, Fecha = fch, Recibido_en = re, correo_electronico = ce, telefono_local = tl, marca = mc, modelo = md, serie = sn, otros = os, servicio = sr};
for i, v in pairs (tbDataToSave) do
TextFile.WriteFromTable(gdr[1], tbDataToSave, false);
if (Application.GetLastError () == 0) then
Dialog.Message ("Guardar orden", "Orden guardada, se comprobará cada dato escrito (12).", MB_OK, MB_ICONINFORMATION, MB_DFBUTTON1);
else
Dialog.Message ("Guardar orden", "Error al crear archivo de orden, intentelo nuevamente.", MB_OK, MB_ICONSTOP, MB_DFBUTTON1);
end
end
end
else
Dialog.Message ("Guardar orden", "No hay datos que guardar.", MB_OK, MB_ICONEXCLAMATION, MB_DFBUTTON1);
end
Sin embargo quiero limpiarlo ya que cuando guardo mi orden comprueba que todos los input tengan algo escrito, ¿como puedo hacer que sea solo un mensaje? y ¿como organizar lo que se copia al bloc de notas?, respondiendo estas preguntas supongo que el tema quedaría muy completo y se pudiese enviar a "Dudas resueltas", gracias de antemano :num1:

bueno si quieres comprobar que sean string vacíos o no ya lo haces, en un solo mensaje? que quieres decir un solo filtro if?

Para organizar una vez editado el txt se trata de extraer la tabla con TextFile.ReadToTable.
Organizar a la tabla como quieras y volver a crear el txt con TextFile.WriteFromTable

Tambien podrias simplificar algo mas el codigo para chequear si las cajas de texto estan vacias o no haciendo esto:
	
ttblInput = {}
for x= 1, 12 do--Total del uno al 12 cajas de textos

tblInput[x] = Input.GetText("Input"..x)
    
    count = Table.Count(tblInput);

    if tblInput[x] == "" and count <= 12 then
    Dialog.Message("Error", "hey hay alguna caja vacia en el formulario por favor rellenelos todos", MB_OK,      MB_ICONINFORMATION, MB_DEFBUTTON1);
    break;
    else
    --pon lo que quieras aqui
    end

end


Bastante practico carsonzillo, siempre y cuando los objetos tengan un nombre secuencial...

Aqui te dejo este ejemplo paisano, lo tenia guardado y lo desbarate y adapte un poco para darte lo que necesitas, ya tiene tiempo que lo hice y quiza encuentres mucho codigo obsoleto, por lo tanto te recomiendo que lo simplifiques y lo mejores. Como siempre, ya que lo hayas logrado esperamos tu ejemplo.

HIDE: ON
Hidebb Message Hidden Description


Saludos viejo ;)

thanks

hey meta tienes buenos ejemplos jajaja gracias!

De hecho ;) gracias de nuevo Meta, por supuesto reportaré un trabajo pulcro. Saludos !!

Graciassss

Thanks

¡Bien!, he terminado mi proyecto pero seguirá en desarrollo, les comparto mi código fuente y algunas capturas de pantalla:

Captura 1:

Imagen

Captura 2:

Imagen

Captura 3:

Imagen

Captura 4:

Imagen

"Como ya lo menciona el programa: Gracias totales a Metafunken"

Código fuente:
--Reaksoft Corporation (C) 2009 - 2013
--Locsoft (C) 2013
--Sistema para Neuron Lap's y PC
--Código Fuente en LUA para Autoplay Media Studio
--Página principal: OnShow
Window.SetSize(Application.GetWndHandle(), 510,520);
--Página principal: Botón 1: OnClic
Page.Jump("Page2");
--Botón 2: OnClic
Page.Jump("Page3");
--Label2: OnClic
Window.SetSize(Application.GetWndHandle(), 1000,530);
--Label3: OnClic
Window.SetSize(Application.GetWndHandle(), 510,530);
--Página de creación de nuevas ordenes de servicio: OnPreload
dId = "Fin de orden";
--Página de creación de nuevas ordenes de servicio: OnShow
local a;
for a=1, 10, 1 do
Input.SetText("Input"..a,"");
end
Window.SetSize(Application.GetWndHandle(), 720, 710);
Fecha = System.GetDate(DATE_FMT_US);
Input.SetText("Input1",Fecha);
--Botón: "Menú principal"
result = Dialog.Message("Ordenes de servicio", "¿Desea ir al Menú Principal?, se perderá cualquier orden no guardada.", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if (result == 6) then
Page.Jump("Page1");
end
--Botón: "Guardar orden"
NuOr = Input.GetText("Input11");
local a;
aCont = true;
tbDataToSave = {};
for a=1, 11, 1 do
allInput=Input.GetText("Input"..a);
if (allInput == "") then
aCont=false;
end
end
if not (aCont) then
Dialog.Message("Guardar nueva orden", "No hay suficiente información para continuar, revise que el formulario este completo.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
Application.ExitScript();
else
Gdr=Dialog.FileBrowse(false, "Guardar orden de servicio", Shell.GetFolder(SHF_DESKTOP), "Archivos de Texto (*.txt)|*.txt|", NuOr , ".txt", false, false);
if (Gdr[1] ~= "CANCEL") and (Gdr[1] ~="") then
for a=1, 11, 1 do
Table.Insert(tbDataToSave, a, Input.GetText("Input"..a));
end
end
Dialog.Message("Guardar nueva orden", "Orden guardada correctamente.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
TextFile.WriteFromTable(Gdr[1], tbDataToSave, false);
TextFile.WriteFromString(Gdr[1], String.Replace(TextFile.ReadToString(Gdr[1]), TextFile.ReadToString(Gdr[1]), TextFile.ReadToString(Gdr[1]).."\r\n".. dId, true), false);
if (Application.GetLastError() ==0) then
for a=1, 11, 1 do
Input.SetText("Input"..a,"");
end
Fecha = System.GetDate(DATE_FMT_US);
Input.SetText("Input1",Fecha);
Input.SetText("Input11","Número de la nueva orden de servicio");
Page.SetFocus("Input11");
else
Dialog.Message("Guardar nueva orden", "Hubo un error al crear orden, intentalo de nuevo.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
end
--Botón: "Nueva Orden"
result = Dialog.Message("Nueva orden de servicio", "Se eliminarán todos los datos del formulario, ¿desea continuar?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if (result == 6) then
local a;
for a=1, 10, 1 do
Input.SetText("Input"..a,"");
end
Fecha = System.GetDate(DATE_FMT_US);
Input.SetText("Input1",Fecha);
Input.SetText("Input11","Número de la nueva orden de servicio");
Page.SetFocus("Input11");
end
--Botón: "Abrir Orden"
tbDataToGet = {};
tbRestL={};
nCL = 0;
Abr=Dialog.FileBrowse(true, "Abrir orden de servicio", Shell.GetFolder(SHF_DESKTOP), "(*.txt)|*.txt|","",".txt",false,false);
if (Abr[1] ~="CANCEL") and (Abr[1] ~="")then
if (String.Find(TextFile.ReadToString(Abr[1]), "\r\n"..dId, 1, true) == -1) then
Dialog.Message("Abrir orden de servicio", "Archivo no válido.\r\n\r\nEste archivo no fue creado a base de este sistema. \r\n\r\nSelecciona un archivo válido e intentalo nuevamente.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
Application.ExitScript();
else
TextFile.WriteFromString(Abr[1], String.Replace(TextFile.ReadToString(Abr[1]), "\r\n"..dId, "", true), false);
 end
 tbDataGet = TextFile.ReadToTable(Abr[1]);
 Line = "";
 for nLine, sData in pairs (tbDataGet) do
 if (nLine == 1) then
 Input.SetText("Input1", sData);
 end
 if (nLine == 2) then
 Input.SetText("Input2", sData);
 end
 if (nLine == 3) then
 Input.SetText("Input3", sData);
 end
 if (nLine == 4) then
 Input.SetText("Input4", sData);
 end
 if (nLine == 5) then
 Input.SetText("Input5", sData);
 end
 if (nLine == 6) then
 Input.SetText("Input6", sData);
 end
 if (nLine == 7) then
 Input.SetText("Input7", sData);
 end
 if (nLine == 8) then
 Input.SetText("Input8", sData);
 end
 if (nLine == 9) then
 Input.SetText("Input9", sData);
 end
 if (nLine == 10) then
 Input.SetText("Input10", sData);
 end
 if (nLine == 11) then
 Input.SetText("Input11", sData);
 end
 TextFile.WriteFromString(Abr[1], String.Replace(TextFile.ReadToString(Abr[1]), TextFile.ReadToString(Abr[1]), TextFile.ReadToString(Abr[1]).."\r\n"..dId, true), true);
 end
 end
 --Botón: "Menú Principal"
 result = Dialog.Message("Ordenes de servicio", "¿Desea ir al Menú Principal?, se perderá cualquier orden no guardada.", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if (result == 6) then
Page.Jump("Page1");
end
--Página 3 "Prestamos a locatarios"
--OnShow de la misma página
local a;
for a=1, 10, 1 do
Input.SetText("Input"..a,"");
end
Window.SetSize(Application.GetWndHandle(), 720, 610);
Fecha = System.GetDate(DATE_FMT_US);
Input.SetText("Input1",Fecha);
--OnPreload de la misma página
dId = "Fin de registro de préstamo para locatario";
--Botón "Guardar registro"
local a;
aCont = true;
tbDataToSave = {};
for a=1, 10, 1 do
allInput=Input.GetText("Input"..a);
if (allInput == "") then
aCont=false;
end
end
if not (aCont) then
Dialog.Message("Guardar nuevo registro de préstamo a locatario", "No hay suficiente información para continuar, revise que el formulario este completo.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
Application.ExitScript();
else
Gdr=Dialog.FileBrowse(false, "Guardar registro", Shell.GetFolder(SHF_DESKTOP), "Archivos de Texto (*.txt)|*.txt|", "Número de registro" , ".txt", false, false);
if (Gdr[1] ~= "CANCEL") and (Gdr[1] ~="") then
for a=1, 10, 1 do
Table.Insert(tbDataToSave, a, Input.GetText("Input"..a));
end
end
Dialog.Message("Guardar nuevo registro", "Préstamo guardado correctamente.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
TextFile.WriteFromTable(Gdr[1], tbDataToSave, false);
TextFile.WriteFromString(Gdr[1], String.Replace(TextFile.ReadToString(Gdr[1]), TextFile.ReadToString(Gdr[1]), TextFile.ReadToString(Gdr[1]).."\r\n".. dId, true), false);
if (Application.GetLastError() ==0) then
for a=1, 10, 1 do
Input.SetText("Input"..a,"");
end
Fecha = System.GetDate(DATE_FMT_US);
Input.SetText("Input1",Fecha);
Page.SetFocus("Input1");
else
Dialog.Message("Guardar nuevo registro", "Hubo un error al crear el registro, intentalo de nuevo.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
end
end
--Botón: "Nuevo registro"
result = Dialog.Message("Nuevo registro de préstamo a locatario", "Se eliminarán todos los datos del formulario, ¿desea continuar?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if (result == 6) then
local a;
for a=1, 10, 1 do
Input.SetText("Input"..a,"");
end
Fecha = System.GetDate(DATE_FMT_US);
Input.SetText("Input1",Fecha);
end
--Botón: "Abrir registro"
tbDataToGet = {};
tbRestL={};
nCL = 0;
Abr=Dialog.FileBrowse(true, "Abrir registro de préstamo a locaterio", Shell.GetFolder(SHF_DESKTOP), "(*.txt)|*.txt|","",".txt",false,false);
if (Abr[1] ~="CANCEL") and (Abr[1] ~="")then
if (String.Find(TextFile.ReadToString(Abr[1]), "\r\n"..dId, 1, true) == -1) then
Dialog.Message("Abrir registro", "Archivo no válido.\r\n\r\nEste archivo no fue creado a base de este sistema. \r\n\r\nSelecciona un archivo válido e intentalo nuevamente.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
Application.ExitScript();
else
TextFile.WriteFromString(Abr[1], String.Replace(TextFile.ReadToString(Abr[1]), "\r\n"..dId, "", true), false);
 end
 tbDataGet = TextFile.ReadToTable(Abr[1]);
 Line = "";
 for nLine, sData in pairs (tbDataGet) do
 if (nLine == 1) then
 Input.SetText("Input1", sData);
 end
 if (nLine == 2) then
 Input.SetText("Input2", sData);
 end
 if (nLine == 3) then
 Input.SetText("Input3", sData);
 end
 if (nLine == 4) then
 Input.SetText("Input4", sData);
 end
 if (nLine == 5) then
 Input.SetText("Input5", sData);
 end
 if (nLine == 6) then
 Input.SetText("Input6", sData);
 end
 if (nLine == 7) then
 Input.SetText("Input7", sData);
 end
 if (nLine == 8) then
 Input.SetText("Input8", sData);
 end
 if (nLine == 9) then
 Input.SetText("Input9", sData);
 end
 if (nLine == 10) then
 Input.SetText("Input10", sData);
 end
 TextFile.WriteFromString(Abr[1], String.Replace(TextFile.ReadToString(Abr[1]), TextFile.ReadToString(Abr[1]), TextFile.ReadToString(Abr[1]).."\r\n"..dId, true), true);
 end
 end
 --Botón: "Menú Principal"
 result = Dialog.Message("Ordenes de servicio", "¿Desea ir al Menú Principal?, se perderá cualquier orden no guardada.", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if (result == 6) then
Page.Jump("Page1");
end
Saludos !! y nueva mente gracias :friends: (Sugiero que no se mueva a Dudas Solucionadas ya que presiento que varias personas van a querer aportar al código)

Gracias r34k, el que me hayas mencionado en los creditos del Soft de tu negocio hace que me sienta honrado.

Vaya manera de corresponder que tienes, se te pedia un solo ejemplo y haz aventado el trabajo completo... Tan solo espero que los demas te agradezcan como se debe pues hay mucho chupasangre que si no ve este tipo de aportes en contenido oculto no agradecen, solo visitan el post y se llevan lo que les sirve sin siquera comentar.

Aun asi esto habla de ti, te felicito por tu aplicacion que de seguro te es util y con eso basta ante las posibles criticas de gente insolente.

Saludos viejo, gracias por agradecer y por supuesto que aqui andamos.
;)

Efectivamente Meta, compartir es vivir :yes: Saludos !! y gracias nuevamente...