problema on transform

problema on transform

Postby carlos vargas » Mon Oct 25, 2021 8:48 pm

Estimados,
Code: Select all  Expand view

 ?transform(8,"@L9999")
 

en harbour y xharbour retorna 0008 lo cual es correcto.
Code: Select all  Expand view

 ?transform(val("8"),"@L9999")
 

en harbour retorna 8, y xharbour 0008, ahi falla harbour
Code: Select all  Expand view

 ?transform("8","@L9999")
 

ambos retornan 8, ahi no se si falla o esta correcto, dado que la ayuda indica que

Syntax
Transform( <xValue>, <cPicture> ) --> cFormattedString

Arguments
<xValue>
This is a value of data type Character, Date, Logic, Memo or Numeric to be formatted.
<cPicture>
This is a PICTURE formatting string defining the formatting rules (see below).


podrian aclarar? por favor...
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1720
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: problema on transform

Postby karinha » Mon Oct 25, 2021 9:18 pm

Code: Select all  Expand view

// \samples\CVARGAS.PRG

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL cString  := "This is Harbour: "
   LOCAL cString2 := "This is xHarbour:"
   LOCAL nNumber  := 9923.34
   LOCAL nNumber1 := -95842.00
   LOCAL lValue   := .T.
   LOCAL dDate    := Date()

   #IFDEF __XHARBOUR__

      // if xHarbour

      ? cString2, Transform( nNumber,  "@L 99999999.99" )  //  "009923.34"

   #ELSE

      // if Harbour

      ? cString,  Transform( nNumber,  "@L 99999999.99" )  //  "009923.34"

   #ENDIF

RETURN NIL
/*
   ? "working with String"
   ? "Current String is",  cString
   ? "All uppercased",  Transform( cString,  "@!" )
   ? "Date is",  ddate
   ? "Date is ",  Transform( ddate,  "@D" )
   ? Transform( 0      ,  "@L 9999"     )  //  "0000"


The table below shows the possible function strings available with the Transform() function.

      @B   Left justify the string within the format.
      @C   Issue a CR after format is numbers are positive.
      @D   Put dates in SET DATE format.
      @E   Put dates in BRITISH format.
      @L   Make a zero padded string out of the number.
      @R   Insert non template characters.
      @X   Issue a DB after format is numbers are negative.
      @Z   Display any zero as blank spaces.
      @(   Quotes around negative numbers
      @!   Convert alpha characters to uppercased format.

The second part of <cTemplate> consists of the format string. Each character in the string may be formatted based on using the follow characters as template markers for the string.

      A,N,X,9,#   Any data type
      L           Shows logical as "T" or "F"
      Y           Shows logical as "Y" or "N"
      !           Convert to uppercase
      $           Dollar sing in place of leading spaces in
                  numeric expression
      *           Asterisks in place of leading spaces in
                  numeric expression
      ,           Commas position
      .           Decimal point position
*/

 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: problema on transform

Postby nageswaragunupudi » Wed Oct 27, 2021 10:55 pm

carlos vargas wrote:Estimados,
Code: Select all  Expand view

 ?transform(8,"@L9999")
 

en harbour y xharbour retorna 0008 lo cual es correcto.
Code: Select all  Expand view

 ?transform(val("8"),"@L9999")
 

en harbour retorna 8, y xharbour 0008, ahi falla harbour
Code: Select all  Expand view

 ?transform("8","@L9999")
 

ambos retornan 8, ahi no se si falla o esta correcto, dado que la ayuda indica que

Syntax
Transform( <xValue>, <cPicture> ) --> cFormattedString

Arguments
<xValue>
This is a value of data type Character, Date, Logic, Memo or Numeric to be formatted.
<cPicture>
This is a PICTURE formatting string defining the formatting rules (see below).


podrian aclarar? por favor...


"@L9999" is not correct
"@L 9999" is correct.
We should separate "@L" and "9999" with one space.
if we give the picture clause correctly, both Harbour and xHarbour give the same results correctly.

Code: Select all  Expand view

   ? Transform( 8,        "@L 9999" ), ;
     Transform( Val("8"), "@L 9999" )
 

Both Harbour and xHarbour produce the same result "0008" in both the cases.

Transform( "8", "@L 9999" ) is NOT CORRECT, because this picture clause applies to numeric values only.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests