5 pts.
 Set a Variable in Hexadecimal Value RPG or CL
Hi everybody, I would like to use variable value for settin color on display, I usually do as follow: D $color S 1A INZ C eval $color = X'28' and obtain color red ! Now my user would like to change it and type 38 into the numeric variable $V1. $v1 = 38 . It seems to me that new command could be: Eval $color = X+''''+$v1+'''' Compiler doesn't issue error, but unfortunatly, in debug mode $color contains 'X' insted of x'38'. Can Someone help me, for RPGLE or CL please ? thanks

Software/Hardware used:
OS400, RPGLE
ASKED: January 11, 2013  6:37 PM
UPDATED: January 11, 2013  6:48 PM

Answer Wiki:
Last Wiki Answer Submitted:  Be the first to answer this question.
All Answer Wiki Contributors:  Be the first to answer this question. CONCORDIA   5 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

More info is needed. You say “…type 38 into the numeric variable $V1″, but you don’t show us how the input field is defined nor how variable $V1 is defined. We can’t guess how the input operation will behave without knowing the definitions.

Then you show the [ Eval $color = X+''''+$v1+'''' ] instruction. But you don’t show the definition of variable X nor of variable $color. It’s not clear if that is an exact copy of the instruction or if you typed it into your question and made an error in typing. You might intend the “X” to be a literal, in which case it probably makes sense that variable $color contains “X”. That’s what you put into it. If you put an “X” into a variable, you should expect to find an “X” there.

We need to see the definitions along with the entire sequence of instructions that alter the values.

Beyond that, having a user type a numeric value into an input variable in order to change a display attribute is trouble. The value is a hexadecimal value, not a decimal value. A user shouldn’t be expected to know anything about hexadecimal display attribute values.

Please describe the actual business problem that you are trying to solve. We can suggest good ways to solve that problem, and it’s almost certain that it won’t be done by typing numeric values in.

Tom

 108,360 pts.

 

Not my styl but perhaps some logic like this.

D CRed C X’28′

Select;
when $v1 = 28;
$Color = CRed;

But why not have the user enter or select the value RED instead of 28?
Phil

 44,220 pts.

 

I consider this a rather dangerous thing to give a user unless you’re editting to make sure they only key in numeric values corresponding to display attributes, but since you asked…

The following RPGLE example shows how to take a 2-digit numeric field an then convert it to a 1-byte character field where the first digit is the first nibble of the byte and the second digit the second nibble. (Note that this editor has historically done very nasty things to my code, so you may have to be just a little flexible when reading this)

h dftactgrp(*No) bnddir(‘QC2LE’)

d CvtCH pr extproc(‘cvtch’)
d Target 1a
d Source 2s 0
d LenSource 10i 0 value

d $V1 s 2s 0
d $Color s 1a

/free

$V1 = 38;
CvtCh($Color :$V1 :%len($V1));

*inlr = *on;
return;

/end-free

The variabe $Color is set to the value x’38′. The same can be do using ILE CL.

Bruce Vining.

 6,055 pts.

 

The whole idea of typing into a numeric field to control a hex value needs more thought since it’ll be tricky typing “2A”, “2B” or any of the other values that use non-numeric hex digits. What is the point? What is the business problem that needs to be solved? — Tom

 108,360 pts.