INTEGER() of a space character(s) - progress-4gl

Does anyone know why INTEGER(" ") is zero in Progress 4GL?
The result is same even if you pass empty string to INTEGER() function. What could be the theory around this? Please help
I have gone through the documentation but couldn't find anything about this.

It's possible that the INTEGER() function does trimming of the input data.
This simple example shows signs of trimming:
DISPLAY INTEGER("1") = INTEGER(" 1 ").
Displays yes
The spaces around the 1 is really not affecting the outcome of the conversion above leading me to think that INTEGER does trimming. Same result for:
DISPLAY INTEGER(" ") = INTEGER("").
I have no real idea as to why INTEGER("") returns 0 and not ? like for instance INTEGER("hello"). I guess it's just a matter of definition.

"Why" is a religious question...
I believe that the 4GL is probably treating a blank string like it would an empty integer fill-in. (Keep in mind that " " is equal to "" in the 4gl.)
Try this:
define variable i as integer no-undo.
i = 2.
update i.
Type a space bar. Notice how the value goes to zero?

"" is a default value for character. If you define a char variable and do not specify INIT value, it will be "". 0 is a default value for integer. So INTEGER("") is very similar to integer with default initial value, which is 0.

Related

how to remove # character from national data type in cobol

i am facing issue while converting unicode data into national characters.
When i convert the Unicode data into national using national-of function, some junk character like # is appended after the string.
E.g
Ws-unicode pic X(200)
Ws-national pic N(600)
--let the value in Ws-Unicode is これらの変更は. getting from java end.
move function national-of ( Ws-unicode ,1208 ) to Ws-national.
--after converting value is like これらの変更は #.
i do not want the extra # character added after conversion.
please help me to find out the possible solution, i have tried to replace N'#' with space using inspect clause.
it worked well but failed in some specific scenario like if we have # in input from user end. in that case genuine # also converted to space.
Below is a snippet of code I used to convert EBCDIC to UTF. Before I was capturing string lengths, I was also getting # symbols:
STRING
FUNCTION DISPLAY-OF (
FUNCTION NATIONAL-OF (
WS-EBCDIC-STRING(1:WS-XML-EBCDIC-LENGTH)
WS-EBCDIC-CCSID
)
WS-UTF8-CCSID
)
DELIMITED BY SIZE
INTO WS-UTF8-STRING
WITH POINTER WS-XML-UTF8-LENGTH
END-STRING
SUBTRACT 1 FROM WS-XML-UTF8-LENGTH
What this code does is string the UTF8 representation of the EBCIDIC string into another variable. The WITH POINTER clause will capture the new length of the string + 1 (+ 1 because the pointer is positioned to the next position after the string ended).
Using this method, you should be able to know exactly how long second string is and use that string with the exact length.
That should remove the unwanted #s.
EDIT:
One thing I forgot to mention, in my case, the # signs were actually EBCDIC low values when viewing the actual hex on the mainframe
Use inspect with reverse and stop after first occurence of #

How do you convert data types in Windows Powershell?

I'm very new to powershell and am running into walls trying to convert a string to a integer.
If I run the following command: Get-DefaultAudioDeviceVolume it often returns a number that looks something like: 50.05816%, which I have confirmed to be a string. I need to convert this to a whole number integer (50). Obviously I could hard code the integer in my script, but for the purpose of the script I need it to be flexible in it's conversion. The result of the previous test changes and I want to pass along the whole integer further down the line.
Thanks in advance!
If the string contains the % symbol you would need to remove this, then you can use the -as operator to convert to [int]
[string]$vol = "50.05816%"
$vol_int = $vol.Replace('%','') -as [int]
The -as operator is very useful and has many other uses, this article goes through a number of them: https://mcpmag.com/articles/2013/08/13/utilizing-the-as-operator.aspx
Just cast it to integer and replace the "%" with nothing:
[int]$var = (Get-DefaultAudioDeviceVolume).Replace("%","")
Powershell does automatic type casting and starts from the left. So when $var is defined as an integer, it will try to convert the right side to the same type.

Checking for an empty ScriptParameter containing text

I am working on FileMaker 14 and am using ScriptParameters. In my parameters I use text, not numbers. I am looking for a way to calculate whether a parameter is empty or not, but the code below returns a 0 value (false) if there is text in ScriptParameter or not:
If [ isEmpty ( Get ( ScriptParamter ) ) ]
The help docs in FileMaker do say that IsEmpty will return a value of 0 if the argument is text. So obviously I am looking for a different calculation or something. Ideas?
Thanks
GW
FileMaker's IsEmpty() function absolutely returns TRUE (1) if a text argument is truly empty. If you're getting false, there's something in your script parameter.
It looks like you might be passing multiple values in your script parameter (based on your use of the plural "script parameters"). If so, your script parameter will never evaluate to true, because of the presence of one or more carriage returns. If you need to pass multiple values, you'll need to first extract a given value using GetValue( Get(ScriptParameter); ), which gets the nth line of text without a trailing carriage return, then test the extracted value.
If that's not right (and you're only passing a single value), this likely means you're passing invisible characters in your script parameter you're not aware of. To test, you can use Length( Get(ScriptParameter) ) to test how many characters FileMaker "sees" in your script parameter. To quickly get a handle on invisible characters, you might use Code( Get(ScriptParameter) ), which will return the ASCII codes for each character. This can quickly reveal if you have spaces, tabs, returns, etc.
The help docs in FileMaker do say that IsEmpty will return a value of
0 if the argument is text.
No, that's most certainly not true. IsEmpty() will return a value of
0 if the argument is empty. If your parameter is of type text, then IsEmpty() will return 0 if and only if the parameter is a string of zero length.

Crystal report issue with int to string conversion

I want to convert int to string and then concatenate dot with it. Here is the formula
totext({#SrNo})+ "."
It works perfectly but not what i want. I want to show at as
1.
but it shows me in this way
1.00.
it means that when i try to convert int to string it convert it into number with precision of two decimal zeros. Can someone tell me how can i show it in proper format. For information i want to tell you that SrNo is running total.
ToText(x, y, z, w) Function can use
x=The number to convert to text
y=The number of decimal places to include in result (optional). The value will be rounded to that decimal place.
z=The character to use as the thousands separator. If you don’t specify one, it will use your application default. (Optional.)
w=The character to use as the decimal separator. If you don’t specify one, it will use your application default. (Optional.)
Examples
ToText(12345.678) = > “12345.678″
ToText(12345.678,2) = > “12345.67″
ToText(12345.678,0) = > “12345″
You can try this :
totext({fieldname},0)
Ohhh I got the answer it was so simple.
totext takes 4 parameters
First parameter is value which is going to be converted
Second parameter is number of decimal previsions.
Third parameter is decimal separator. like (1,432.123) here dot(.) is third parameter.
Forth parameter is thousand separator. like (1,432) here comma(,) is forth parameter.
Example{
totext("1,432.1234",2) results 1,432.12
totext("1,432.1234",2,' " ') results 1,432"1234
totext("1,432.1234",2,' " ', ' : ') results 1:432,1234
}
Although i think this example may be not so good but i just want to give you an idea. This is for int conversion for date it has 2 parameters.
value to be converted and format of date.

Perl autoincrement of string not working as before

I have some code where I am converting some data elements in a flat file. I save the old:new values to a hash which is written to a file at the end of processing. On subsequence execution, I reload into a hash so I can reuse previously converted values on additional data files. I also save the last conversion value so if I encounter an unconverted value, I can assign it a new converted value and add it to the hash.
I had used this code before (back in Feb) on six files with no issues. I have a variable that is set to ZCKL0 (last character is a zero) which is retrieved from a file holding the last used value. I apply the increment operator
...
$data{$olddata} = ++$dataseed;
...
and the resultant value in $dataseed is 1 instead of ZCKL1. The original starting seed value was ZAAA0.
What am I missing here?
Do you use the $dataseed variable in a numeric context in your code?
From perlop:
If you increment a variable that is
numeric, or that has ever been used in
a numeric context, you get a normal
increment. If, however, the variable
has been used in only string contexts
since it was set, and has a value that
is not the empty string and matches
the pattern /^[a-zA-Z][0-9]\z/ , the
increment is done as a string,
preserving each character within its
range.
As prevously mentioned, ++ on strings is "magic" in that it operates differently based on the content of the string and the context in which the string is used.
To illustrate the problem and assuming:
my $s='ZCL0';
then
print ++$s;
will print:
ZCL1
while
$s+=0; print ++$s;
prints
1
NB: In other popular programming languages, the ++ is legal for numeric values only.
Using non-intuitive, "magic" features of Perl is discouraged as they lead to confusing and possibly unsupportable code.
You can write this almost as succinctly without relying on the magic ++ behavior:
s/(\d+)$/ $1 + 1 /e
The e flag makes it an expression substitution.