DUDA

  • Este debate tiene 4 respuestas, 2 mensajes y ha sido actualizado por última vez el 4 meses, 2 semanas por Avatardmillas. This post has been viewed 152 times
Mostrando 4 respuestas a los debates
  • Autor
    Entradas
    • #2175
      Avatardmillas
      Participante

      Hola.

      Os adjunto codigo de una tabla que estoy realizando  tengo unas dudas, las dudas no son de nefele pero creo que me podreis ayudar

      PROCEDURE MainPage()
      LOCAL X,Y,REGISTROS
      REGISTROS := 5

      With Object TWebPage():New()
      :lValign := .T.
      with object WForm():New(:WO)
      :cid := "F_Tabla"
      :cFunction := "VISPARAM"
      FOR X=1 TO REGISTROS
      With Object WLabel():New(:WO)
      :cText := "DATO "+NFL_VALTOJS(X)
      :lBR := .T.
      :aWidth := {3,3,,}
      :aOffset := {0,0,,}
      :Create()
      END WITH
      WITH OBJECT WEdit():New(:WO)
      :cId := "VALOR_"+NFL_VALTOJS(X)
      :cValue :=NFL_VALTOJS(1000+X)
      :lEnabled := .F.
      :aWidth := {0,3,,}
      :Create()
      END with
      WITH OBJECT WEdit():New(:WO)
      :cId := "MED_"+NFL_VALTOJS(X)
      :nTimeOut := 0.1
      :cAjaxTimeOut := "CALCULOS"
      :cTitle := "MED. MM"
      :lEnabled := .T.
      :aWidth := {3,2,,}
      FOR Y=1 TO REGISTROS
      :AddParam({"VALOR_"+NFL_VALTOJS(Y),"#VALOR_"+NFL_VALTOJS(Y)})
      IF (Y<>X, :AddParam({"MED_"+NFL_VALTOJS(Y),"#MED_"+NFL_VALTOJS(Y)}),)
      NEXT Y
      :Create()
      END with
      WITH OBJECT WEdit():New(:WO)
      :cId := "DIFERENCIA"+NFL_VALTOJS(X)
      :lEnabled := .F.
      :aWidth := {3,2,,}
      :Create()
      END with
      WITH OBJECT WEdit():New(:WO)
      :cId := "VARIACION"+NFL_VALTOJS(X)
      :lEnabled := .F.
      :aWidth := {3,2,,}
      :Create()
      END with
      NEXT X
      :Create()
      End With
      oCgi:SendPage( :Create() ) // Se crea el HTML final y se envía al navegador saliendo del ejecutable CGI
      End With
      RETURN

      //------------------------------------------------------------------------------

      PROCEDURE CALCULOS() //DATOS PUNTUACION REVISADOS
      LOCAL cSalida
      LOCAL DIF1,DIF2,DIF3,DIF4,DIF5
      LOCAL VAR2,VAR3,VAR4,VAR5
      LOCAL PRU,X,P
      LOCAL MED,DEST

      DIF1 := Val(oCGI:GetCgiValue("VALOR_1"))-Val(oCGI:GetCgiValue("MED_1"))
      DIF2 := Val(oCGI:GetCgiValue("VALOR_2"))-Val(oCGI:GetCgiValue("MED_2"))
      DIF3 := Val(oCGI:GetCgiValue("VALOR_3"))-Val(oCGI:GetCgiValue("MED_3"))
      DIF4 := Val(oCGI:GetCgiValue("VALOR_4"))-Val(oCGI:GetCgiValue("MED_4"))
      DIF5 := Val(oCGI:GetCgiValue("VALOR_5"))-Val(oCGI:GetCgiValue("MED_5"))
      //
      //
      //

      VAR2 :=Abs(DIF2-DIF1)
      VAR3 :=Abs(DIF3-DIF2)
      VAR4 :=Abs(DIF4-DIF3)
      VAR5 :=Abs(DIF5-DIF4)
      //
      //
      //

      MED=(VAR2+VAR3+VAR4+VAR5)/4
      DEST=SQRT(((VAR2-MED)^2+(VAR3-MED)^2+(VAR4-MED)^2+(VAR5-MED)^2)/4)

      text into cSalida
      document.getElementById('diferencia1').value='[[diferencia1]]';
      document.getElementById('diferencia2').value='[[diferencia2]]'
      document.getElementById('diferencia3').value='[[diferencia3]]';
      document.getElementById('diferencia4').value='[[diferencia4]]'
      document.getElementById('diferencia5').value='[[diferencia5]]';
      //
      //
      //
      //
      document.getElementById('variacion2').value='[[variacion2]]';
      document.getElementById('variacion3').value='[[variacion3]]';
      document.getElementById('variacion4').value='[[variacion4]]';
      document.getElementById('variacion5').value='[[variacion5]]';
      //
      //
      //
      //
      endtext

      cSalida := StrTran(cSalida, "[[diferencia1]]", NFL_VALTOJS(DIF1))
      cSalida := StrTran(cSalida, "[[diferencia2]]", NFL_VALTOJS(DIF2))
      cSalida := StrTran(cSalida, "[[diferencia3]]", NFL_VALTOJS(DIF3))
      cSalida := StrTran(cSalida, "[[diferencia4]]", NFL_VALTOJS(DIF4))
      cSalida := StrTran(cSalida, "[[diferencia5]]", NFL_VALTOJS(DIF5))
      //
      //
      //
      //
      cSalida := StrTran(cSalida, "[[variacion2]]", NFL_VALTOJS(VAR2))
      cSalida := StrTran(cSalida, "[[variacion3]]", NFL_VALTOJS(VAR3))
      cSalida := StrTran(cSalida, "[[variacion4]]", NFL_VALTOJS(VAR4))
      cSalida := StrTran(cSalida, "[[variacion5]]", NFL_VALTOJS(VAR5))
      //
      //
      //
      //
      oCGI:SendScript( cSalida )
      RETURN

       

       

      Puedo variar el nº de registros segun se pida, 20, 30, 5 etc, no tengo problema para la adquisicion de datos en el mainPage, según se defina la varible registros monta la pagina para obtener los datos.

      El problema me surge en la funcion calculos() es posible definir la variables en función del numero de registros, asi como los calculos DIFn y VARn asi como las lineas del Tex into y la posterior sustitucion con StrTran.

      a lo bestia podria hacer una funcion para cafa valor de registros, pero seria un monton de lineas de codigo.

       

       

      Loading spinner
    • #2176
      Avatardmillas
      Participante

      Hola.

      Ya lo he conseguido!! monto un array con las dimensiones de registros y guardo los valores que calculo y los sustituyo en pantalla.

      Me he quedado atascado con el "text into cSalida" guardo el mismo texto en una variable que llamo texto pero no me funciona al hacer oCGI:SendScript(TEXTO)

      la variable texto y cSalida son iguales y no lo entiendo.

      he probado

      cSalida = TEXTO

      oCGI:SendScript(TEXTO)

       

       

      #include "Xailer.ch"
      #include "Nefele.ch"

      //------------------------------------------------------------------------------

      PROCEDURE MainPage()
      LOCAL X,Y,REGISTROS
      REGISTROS := 5

      With Object TWebPage():New()
      :lValign := .T.
      with object WForm():New(:WO)
      :cid := "F_Tabla"
      :cFunction := "VISPARAM"
      FOR X=1 TO REGISTROS
      With Object WLabel():New(:WO)
      :cText := "DATO "+NFL_VALTOJS(X)
      :lBR := .T.
      :aWidth := {3,3,,}
      :Create()
      END WITH
      WITH OBJECT WEdit():New(:WO)
      :cId := "VALOR_"+NFL_VALTOJS(X)
      :cValue :=NFL_VALTOJS(1000+X)
      :lEnabled := .F.
      :aWidth := {0,3,,}
      :Create()
      END with
      WITH OBJECT WEdit():New(:WO)
      :cId := "MED_"+NFL_VALTOJS(X)
      :nTimeOut := 0.1
      :cAjaxTimeOut := "CALCULOS"
      :cTitle := "MED. MM"
      :lEnabled := .T.
      :aWidth := {3,2,,}
      FOR Y=1 TO REGISTROS
      :AddParam({"VALOR_"+NFL_VALTOJS(Y),"#VALOR_"+NFL_VALTOJS(Y)})
      IF (Y<>X, :AddParam({"MED_"+NFL_VALTOJS(Y),"#MED_"+NFL_VALTOJS(Y)}),)
      NEXT Y
      :Create()
      END with
      WITH OBJECT WEdit():New(:WO)
      :cId := "DIFERENCIA"+NFL_VALTOJS(X)
      :lEnabled := .F.
      :aWidth := {3,2,,}
      :Create()
      END with
      WITH OBJECT WEdit():New(:WO)
      :cId := "VARIACION"+NFL_VALTOJS(X)
      :lEnabled := .F.
      :aWidth := {3,2,,}
      :Create()
      END with
      NEXT X
      :Create()
      End With
      oCgi:SendPage( :Create() )
      End With
      RETURN

      //------------------------------------------------------------------------------

      PROCEDURE CALCULOS()
      LOCAL cSalida
      LOCAL X,TEXTO :=""
      LOCAL MED,DEST
      LOCAL TABLA :={}

      FOR X=1 TO 5
      IF X<2
      AAdd(TABLA,;
      {Val(oCGI:GetCgiValue("VALOR_"+NFL_VALTOJS(X)))-Val(oCGI:GetCgiValue("MED_"+NFL_VALTOJS(X))),;
      "",;
      "document.getElementById('diferencia"+NFL_VALTOJS(X)+"').value='[[diferencia"+NFL_VALTOJS(X)+"]]'",""})
      ELSE
      AAdd(TABLA,;
      {Val( oCGI:GetCgiValue("VALOR_"+NFL_VALTOJS(X)))-Val(oCGI:GetCgiValue("MED_"+NFL_VALTOJS(X))),;
      Abs((Val(oCGI:GetCgiValue("VALOR_"+NFL_VALTOJS(X)))-Val(oCGI:GetCgiValue("MED_"+NFL_VALTOJS(X))))-(Val(oCGI:GetCgiValue("VALOR_"+NFL_VALTOJS(X-1)))-Val(oCGI:GetCgiValue("MED_"+NFL_VALTOJS(X-1))))),;
      "document.getElementById('diferencia"+NFL_VALTOJS(X)+"').value='[[diferencia"+NFL_VALTOJS(X)+"]]'","document.getElementById('variacion"+NFL_VALTOJS(X)+"').value='[[variacion"+NFL_VALTOJS(X)+"]]'"})
      ENDIF
      NEXT

      FOR X=1 TO 5
      TEXTO =TEXTO+TABLA[X,3]
      NEXT
      FOR X=2 TO 5
      TEXTO =TEXTO+TABLA[X,4]
      NEXT

      //MED=(VAR2+VAR3+VAR4+VAR5)/4
      //DEST=SQRT(((VAR2-MED)^2+(VAR3-MED)^2+(VAR4-MED)^2+(VAR5-MED)^2)/4)

      TEXT into cSalida
      document.getElementById('diferencia1').value='[[diferencia1]]'
      document.getElementById('diferencia2').value='[[diferencia2]]'
      document.getElementById('diferencia3').value='[[diferencia3]]'
      document.getElementById('diferencia4').value='[[diferencia4]]'
      document.getElementById('diferencia5').value='[[diferencia5]]'
      document.getElementById('variacion2').value='[[variacion2]]'
      document.getElementById('variacion3').value='[[variacion3]]'
      document.getElementById('variacion4').value='[[variacion4]]'
      document.getElementById('variacion5').value='[[variacion5]]'
      endtext

      FOR X=1 TO 5
      cSalida := StrTran(cSalida, "[[diferencia"+NFL_VALTOJS(X)+"]]", NFL_VALTOJS(TABLA[X,1]))
      TEXTO := StrTran(TEXTO, "[[diferencia"+NFL_VALTOJS(X)+"]]", NFL_VALTOJS(TABLA[X,1]))
      IF(X>=2,cSalida := StrTran(cSalida, "[[variacion"+NFL_VALTOJS(X)+"]]",NFL_VALTOJS(TABLA[X,2])),)
      IF(X>=2,TEXTO := StrTran(TEXTO, "[[variacion"+NFL_VALTOJS(X)+"]]",NFL_VALTOJS(TABLA[X,2])),)
      NEXT
      NFL_CONSOLE(cSalida)
      NFL_CONSOLE(TEXTO)
      // oCGI:SendScript(TEXTO)
      oCGI:SendScript( cSalida )
      RETURN

      Loading spinner
    • #2177
      Avatardmillas
      Participante

      Hola.

      Ya lo he conseguido,

      solo faltaba por ; despues de cada linea "document.getElementById('diferenciax').value='[[diferenciax]]';"

       

       

      Loading spinner
    • #2178
      Alfredo SanzAlfredo Sanz
      Superadministrador

      Holaqtal.

      En teoría no tendría que hacer falta. Si hay un retorno de línea, en js se puede quitar el ;

      Mira el texto que se genera en el navegador y dime si las líneas están juntas o están en líneas diferentes.

       

       

      Loading spinner
    • #2179
      Avatardmillas
      Participante

      Hola.

      Sale todo junto ponga o no ponga ; la diferencia es que si pongo ; hace la sustitución y si no pongo ; no la hace.

      Loading spinner
Mostrando 4 respuestas a los debates
  • Debes estar registrado para responder a este debate.

Si continuas utilizando este sitio aceptas el uso de cookies. más información

Los ajustes de cookies de esta web están configurados para «permitir cookies» y así ofrecerte la mejor experiencia de navegación posible. Si sigues utilizando esta web sin cambiar tus ajustes de cookies o haces clic en «Aceptar» estarás dando tu consentimiento a esto.

Cerrar