string to parameter

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 236
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 2 times
Contact:

string to parameter

Post by jairpinho » 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

Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
andyglezl
Posts: 1027
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » 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
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
jairpinho
Posts: 236
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 2 times
Contact:

Post by jairpinho » Wed Oct 24, 2018 3:32 pm

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
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
andyglezl
Posts: 1027
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » Wed Oct 24, 2018 4:06 pm

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
Andrés González López
Desde Guadalajara, Jalisco. México.

edk
Posts: 360
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Wed Oct 24, 2018 5:59 pm

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)

User avatar
andyglezl
Posts: 1027
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » 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 }
Andrés González López
Desde Guadalajara, Jalisco. México.

edk
Posts: 360
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Wed Oct 24, 2018 6:52 pm

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.

User avatar
andyglezl
Posts: 1027
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » Wed Oct 24, 2018 8:00 pm

Entonces, &cColorx debería de funcionar
---------------------------------------------------
So, &cColorx should work

Local cColorx := oRow: fieldGet (28) // "RED"
Local aColor := &cColorx // { 255 , 0 , 0 }
Andrés González López
Desde Guadalajara, Jalisco. México.

edk
Posts: 360
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Wed Oct 24, 2018 8:21 pm

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

User avatar
andyglezl
Posts: 1027
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » Wed Oct 24, 2018 10:21 pm

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
Andrés González López
Desde Guadalajara, Jalisco. México.

Post Reply