Page 1 of 2

string to parameter

Posted: Wed Oct 24, 2018 2:35 pm
by jairpinho
Hi everyone, I am having problems using standard compiler colors through a string variable I do not know how to do it already used macro & but it does not work

Code: Select all

Local cColor := "RED"


@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR RED CENTER   // -> its ok
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR cColor CENTER  //  -> does not work

@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR &cColor CENTER  //  -> does not work


Re: string to parameter

Posted: Wed Oct 24, 2018 3:19 pm
by andyglezl
Cual es la razón de ponerle las comillas ?
---------------------------------------------------
What is the reason for putting the quotes?

Local cColor := RED
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR cColor CENTER // -> it should work

Re: string to parameter

Posted: Wed Oct 24, 2018 3:32 pm
by jairpinho
andyglezl wrote: Wed Oct 24, 2018 3:19 pm Cual es la razón de ponerle las comillas ?
---------------------------------------------------
What is the reason for putting the quotes?

Local cColor := RED
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR cColor CENTER // -> it should work
this color will fetch in a mysql database of type string = oRow: fieldGet (28) = "RED" needs to be interpreted as a color definition and not as a string

Re: string to parameter

Posted: Wed Oct 24, 2018 4:06 pm
by andyglezl
Maybe...

Local cColorx := oRow: fieldGet (28) // "RED"
Local aColor := &cColorx
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR aColor CENTER // -> it should work

Re: string to parameter

Posted: Wed Oct 24, 2018 5:59 pm
by edk
jairpinho wrote: Wed Oct 24, 2018 2:35 pm Hi everyone, I am having problems using standard compiler colors through a string variable I do not know how to do it already used macro & but it does not work

Code: Select all

Local cColor := "RED"


@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR RED CENTER   // -> its ok
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR cColor CENTER  //  -> does not work

@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR &cColor CENTER  //  -> does not work

It will not work because RED, BLACK, WHITE, BLUE, etc are not variables but definitions.
Try to assign variables to the corresponding definitions, for example (case sensitive are important!):

Code: Select all

black  := BLACK
white  := WHITE
gray   := GRAY
red    := RED
green  := GREEN
blue   := BLUE
cyan   := CYAN
yellow := YELLOW
pink   := PINK
fuchsia:= FUCHSIA
brown  := BROWN
orange := ORANGE
purple := PURPLE

silver := SILVER
maroon := MAROON
olive  := OLIVE
lgreen := LGREEN
aqua   := AQUA
navy   := NAVY
teal   := TEAL

cColorRed := "Red"		//"RED", "red", "Red", "rED": here case sensitive is not important
cColorBlue := "Blue" 

msgdebug (&cColorRed, &cColorBlue)

Re: string to parameter

Posted: Wed Oct 24, 2018 6:10 pm
by andyglezl
???
En i_color.ch están definidos...
------------------------------------------
???
In i_color.ch they are defined ...

---------------------------------------------------------------------------*/
#define BLACK { 0 , 0 , 0 }
#define WHITE { 255 , 255 , 255 }
#define GRAY { 128 , 128 , 128 }
#define RED { 255 , 0 , 0 }
#define GREEN { 0 , 255 , 0 }
#define BLUE { 0 , 0 , 255 }
#define CYAN { 153 , 217 , 234 }
#define YELLOW { 255 , 255 , 0 }
#define PINK { 255 , 128 , 192 }
#define FUCHSIA { 255 , 0 , 255 }
#define BROWN { 128 , 64 , 64 }
#define ORANGE { 255 , 128 , 64 }
#define PURPLE { 128 , 0 , 128 }

Re: string to parameter

Posted: Wed Oct 24, 2018 6:52 pm
by edk
andyglezl wrote: Wed Oct 24, 2018 6:10 pm ???
En i_color.ch están definidos...
------------------------------------------
???
In i_color.ch they are defined ...

---------------------------------------------------------------------------*/
#define BLACK { 0 , 0 , 0 }
#define WHITE { 255 , 255 , 255 }
#define GRAY { 128 , 128 , 128 }
#define RED { 255 , 0 , 0 }
#define GREEN { 0 , 255 , 0 }
#define BLUE { 0 , 0 , 255 }
#define CYAN { 153 , 217 , 234 }
#define YELLOW { 255 , 255 , 0 }
#define PINK { 255 , 128 , 192 }
#define FUCHSIA { 255 , 0 , 255 }
#define BROWN { 128 , 64 , 64 }
#define ORANGE { 255 , 128 , 64 }
#define PURPLE { 128 , 0 , 128 }
Yes, but these are definitions, not variables.
Macro (&) works with variables, not with definitions.

Variables are processed in RAM, while definitions are replaced by the compiler on their values during consolidation.

Re: string to parameter

Posted: Wed Oct 24, 2018 8:00 pm
by andyglezl
Entonces, &cColorx debería de funcionar
---------------------------------------------------
So, &cColorx should work

Local cColorx := oRow: fieldGet (28) // "RED"
Local aColor := &cColorx // { 255 , 0 , 0 }

Re: string to parameter

Posted: Wed Oct 24, 2018 8:21 pm
by edk
Unfortunately, it will not work.
The variable cColorx will take the value "RED", then you try to read the value of the variable RED, which does not exist.
RED is a constant of {255,0,0}

Try to make a simple test:
such source code will be compiled correctly:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

ANYNUMERIC := 1

ANYNUMERIC ++

MSGBOX (ANYNUMERIC)

RETURN
however, this source code will not compile at all:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

#define ANYNUMERIC 1

ANYNUMERIC ++

MSGBOX (ANYNUMERIC)
RETURN
and is equivalent to such source code

Code: Select all

#include "hmg.ch"

FUNCTION Main()

1 ++

MSGBOX (1)
RETURN

See: https://stackoverflow.com/questions/110 ... s-variable

Re: string to parameter

Posted: Wed Oct 24, 2018 10:21 pm
by andyglezl
mmmm... Chequé algunos de mis fuentes y en ninguno utilizo la forma que quiere utilizar jairpinho
-------------------------------------------------------------------------------------------------------------------------------
mmmm ... I checked some of my sources and in none I use the form that wants to use jairpinho