how can I split this barcode by group separator with Progress? I've tried chr(29) without any luck.
Barcode scanned into Notepad++: http://i.imgur.com/8DmPZ.png
Barcode scanned into input field: 2409271405202120330017100282
Thanks.
def var c as char no-undo.
def var i as int no-undo.
update c format "x(50)".
do i = 1 to length(c):
message substr(c, i, 1) = chr(29).
end.
The problem is that GS is an undefined control code. So you need to make it be recognized.
Add the following to your terminal's entry in protermcap to define GS as F13:
:(F13)=\035:\
(The octal code for GS is \035 and F13 is an undefined function key -- so the combination should work. I don't have a scanner to test with but this works for the control codes that I can type into my keyboard...)
Then use code like this:
define variable bc as character no-undo format "X(50)".
update bc editing:
if lastkey = 313 then
apply ".". /* 313 is the code for F13 */
else
apply lastkey.
end.
This should cause "." to be inserted instead of GS. Which will allow you to parse the string using "." rather than GS.
It's a wild guess, but I'm thinking ENTRY(entry-num, barcode-string, "group-separator-string")?
This works for me:
/* create a test file (otherwise not needed...)
*/
output to "barcode.dat".
put control "240927140520" chr(29) "2120330017" chr(29) "100282".
output close.
/* if you already have barcode.dat start here
*/
define variable m as memptr no-undo.
define variable bc as character no-undo.
set-size( m ) = 100.
input from "barcode.dat" binary no-convert.
import unformatted m.
input close.
bc = get-string( m, 1 ).
display
entry( 1, bc, chr(29)) format "x(12)" skip
entry( 2, bc, chr(29)) format "x(12)" skip
entry( 3, bc, chr(29)) format "x(12)" skip
.
Related
Want to print a row/column table that is formatted as in a typical
fmt.Printf("%5s %5s %5s\n",col1, col2, col3)
Works fine of course if the strings are plain text, but if a string has display attributes
like color, bold, font - even though the visible data is the same length as the plain text,
and would be fine in %5s; doing len(col1) is much longer it skews the table alignment.
Is there a way for Printf to accomplish this, or another std Go package?
Want:
Item Item Item
===== ===== ====
abc defgh xyz
x abc d
vv xxxxx zz <=== this happens if string xxxxx has display attributes from
fatih,gchalk, etc. to set foreground/background color
`
//
package main
import (
"fmt"
"github.com/jwalton/gchalk"
"github.com/fatih/color"
)
func main() {
var colorWithGchalk = gchalk.Red
var data = []string{"one", "ten", "twenty"}
gchalk.SetLevel(gchalk.LevelAnsi16m) // seems needed for gitbash
// note output columns framed by <> just to see actual width
fmt.Println("desired formatted output")
fmt.Printf("<%-10s> <%-10s> <%-10s>\n\n", data[0],data[1],data[2])
/*
** gchalk
*/
// first try using gchalk for color
// colorize second column - column width ignored?
fmt.Println("colorized field loses its 10 character width, so subsequent fields now misaligned")
fmt.Printf("<%-10s> <%-10s> <%-10s>\n", data[0], colorWithGchalk(data[1]), data[2])
// same as above but eliminate gchalk function and just apply colorizing directly - same result
fmt.Printf("<%-10s> <%-10s> <%-10s>\n", data[0], gchalk.Red(data[1]), data[2])
/*
** fatih
*/
fmt.Println("\nwith fatih")
var colorWithFatih = color.New(color.FgRed).SprintFunc()
fmt.Printf("<%-10s> <%-10s> <%-10s>\n", data[0], colorWithFatih(data[1]), data[2])
}
`
Output:
`
desired formatted output
colorized field loses its 10 character width,
so subsequent fields now misaligned
with fatih
`
On screen the above 3 lines display the word "ten" in red as desired, but the field is no longer 10 wide.
Is there a way for Printf to accomplish this,
No
or another std Go package?
No
(What you call "display attributes" are part of the output stream of bytes, they are not "attributes", this is "inline data" interpreted by the terminal emulator. What you can do is filter out this inline data before printing.)
You could use https://github.com/olekukonko/tablewriter as an example for how to output tables or just use the package.
With the advice of Jason Walton the porter of chalk to gchalk. I got fmt.Printf %s to satisfy my need, although their may be issues if the field widths (%s) were narrow.
I wanted to concatenate at least two strings together to provide to one %s.
The first string was plain text (sgCharToPrint) the next string was colorized so it was the actual screen text (missedRaw) (missed was the color string e.g. missedRaw wrapped with ansi formatting characters.
myLen = len(sgCharToPrint) + len(missedRaw)
padded = sgCharToPrint + missed + strings.Repeat(" ", 30 - olen)
fmt.Printf("%30s %4d %10s \n",padded, value, tail)
Now the "table" display stays in alignment.
I would like to generate multiple plots within one gnuplot script, and would like to start each plot's title with a running capital letter, i.e., the first plot will have the title (A) sample title for first chart, the second one (B) sample title for second chart, and so on.
In Java, for this I basically have to do
int i = 65; // ASCII value for 65
char c = (char)i; // Convert 65 to corresponding ASCII value ('A')
i++;
// Use c; then repeat
I just tried something similar in gnuplot by using gprintf and using the %c formatter, yet I could not get it working due to the problem
These format specifiers are not the same as those used by the standard C-language routine sprintf().
Long question short: How to convert an integer to its corresponding ASCII value?
gnuplot> print sprintf("%c", 65)
#A
Gnuplot provides a gprintf which uses gnuplot format specifiers and sprintf.
using visualworks, in small talk, I'm receiving a string like '31323334' from a network connection.
I need a string that reads '1234' so I need a way of extracting two characters at a time, converting them to what they represent in ascii, and then building a string of them...
Is there a way to do so?
EDIT(7/24): for some reason many of you are assuming I will only be working with numbers and could just truncate 3s or read every other char. This is not the case, examples of strings read could include any keys on the US standard keyboard (a-z, A-Z,0-9,punctuation/annotation such as {}*&^%$...)
Following along the lines of what Max started to suggest:
x := '31323334'.
in := ReadStream on: x.
out := WriteStream on: String new.
[ in atEnd ] whileFalse: [ out nextPut: (in next digitValue * 16 + (in next digitValue)) asCharacter ].
newX := out contents.
newX will have the result '1234'. Or, if you start with:
x := '454647'
You will get a result of 'EFG'.
Note that digitValue might only recognize upper case hex digits, so an asUppercase may be needed on the string before processing.
There is usually a #fold: or #reduce: method that will let you do that. In Pharo there's also a message #allPairsDo: and #groupsOf:atATimeCollect:. Using one of these methods you could do:
| collectionOfBytes |
collectionOfBytes := '9798'
groupsOf: 2
atATimeCollect: [ :group |
(group first digitValue * 10) + (group second digitValue) ].
collectionOfBytes asByteArray asString "--> 'ab'"
The #digitValue message in Pharo simply returns the value of the digit for numerical characters.
If you're receiving the data on a stream you could replace #groupsOf:atATime: with a loop (result may be any collection that you then convert to a string like above):
...
[ stream atEnd ] whileFalse: [
result add: (stream next digitValue * 10) + (stream next digitValue) ]
...
in Smalltalk/X, there is a method called "fromHexBytes:" which the ByteArray class understands. I am not sure, but think that something similar exists in other ST dialects.
If present, you can solve this with:
(ByteArray fromHexString:'68656C6C6F31323334') asString
and the reverse would be:
'hello1234' asByteArray hexPrintString
Another possible solution is to read the string as a hex number,
fetch the digitBytes (which should give you a byte array) and then convert that to a string.
I.e.
(Integer readFrom:'68656C6C6F31323334' radix:16)
digitBytes asString
One problem with that is that I am not sure about which byte-order you will get the digitBytes (LSB or MSB), and if that is defined to be the same across architectures or converted at image loading time to use the native order. So it may be required to reverse the string at the end (to be portable, it may even be required to reverse it conditionally, depending on the endianess of the system.
I cannot test this on VisualWorks, but I assume it should work fine there, too.
I have MATLAB set to record three webcams at the same time. I want to capture and save each feed to a file and automatically increment it the file name, it will be replaced by experiment_0001.avi, followed by experiment_0002.avi, etc.
My code looks like this at the moment
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
avi1 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_002.AVI');
avi2 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI');
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
and I am incrementing the 002 each time.
Any thoughts on how to implement this efficiently?
Thanks.
dont forget matlab has some roots to C programming language. That means things like sprintf will work
so since you are printing out an integer value zero padded to 3 spaces you would need something like this sprintf('%03d',n) then % means there is a value to print that isn't text. 0 means zero pad on the left, 3 means pad to 3 digits, d means the number itself is an integer
just use sprintf in place of a string. the s means String print formatted. so it will output a string. here is an idea of what you might do
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
for (n=1:2:max_num_captures)
avi1 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_%03d.AVI',n));
avi2 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI',n));
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
end
I have put 2 fields into a barcode and an additional delimiter also. The barcode content will be for example 123456789|abcdefg where pipe is the delimiter.
Now i have to sacn this barcode once and then make the first part appear in one field and 2nd part ie whatever is after the | in the seconf field in progress 4gl? How can i do it??
You can create the first field formatted as it can handle all the code. Then, into the RETURN event of the field (assuming that you using an SmartWindow and your barcode reader do a CR/LF at the end of barcode reading) you use the content of the first field and split it into two fields. Something like this :
DEF VAR cField1 AS CHAR NO-UNDO FORMAT 'x(50)'.
DEF VAR cField2 AS CHAR NO-UNDO FORMAT 'x(50)'.
UPDATE cField1 WITH WIDTH 333. /* Here you 'bip' your barcode */
ASSIGN cField2 = ENTRY(2,cField1,'|')
cField1 = ENTRY(1,cField1,'|').
DISP cField1 cField2.
Hope it helps.