i am trying to Cut paper after every line in VB6 here is the code
Open "LPT1" For Output As #1
Print #1, Chr$(&H1B); "#"; 'Initializes the printer (ESC #)
Print #1, Chr$(&H1B); "d"; Chr$(0); 'Prints and line feeding (ESC d)
Print #1, Chr$(&H1B); "!"; Chr$(17); 'Selects double-height mode
For a = 1 To 5
Print #1, "14-January Invoice 01000"; Chr$(&HA); 'Prints and line feed
Print #1, Chr$(&H1B); "m"; Chr$(&HA); 'Cut Paper
Next
Print #1, Chr$(&H1D); "V"; Chr$(66); Chr$(0);
Close #1
it should be printing a line after then cut the paper but it start cutting paper from the top
any body can help me on this?
update: basically what i want is to make small tags where date and invoice written on it and tag max 1 cm long.
You are performing a partial cut (ESC m) inside of your loop, after every line you are printing. I think you probably want to remove that line:
Print #1, Chr$(&H1B); "m"; Chr$(&HA); 'Cut Paper
After the loop, you then perform a feed-and-cut (partial cut) operation (GS V 66 0) after the loop completes. I think you probably want to keep that line to perform the cut after you've printed.
Related
Chapter 3 of Starting FORTH says,
Now that you've made a block "current", you can list it by simply typing the word L. Unlike LIST, L does not want to be proceeded by a block number; instead it lists the current block.
When I run 180 LIST, I get
Screen 180 not modified
0
...
15
ok
But when I run L, I get an error
:30: Undefined word
>>>L<<<
Backtrace:
$7F0876E99A68 throw
$7F0876EAFDE0 no.extensions
$7F0876E99D28 interpreter-notfound1
What am I doing wrong?
Yes, gForth supports an internal (BLOCK) editor. Start gforth
type: use blocked.fb (a demo page)
type: 1 load
type editor
words will show the editor words,
s b n bx nx qx dl il f y r d i t 'par 'line 'rest c a m ok
type 0 l to list screen 0 which describes the editor,
Screen 0 not modified
0 \\ some comments on this simple editor 29aug95py
1 m marks current position a goes to marked position
2 c moves cursor by n chars t goes to line n and inserts
3 i inserts d deletes marked area
4 r replaces marked area f search and mark
5 il insert a line dl delete a line
6 qx gives a quick index nx gives next index
7 bx gives previous index
8 n goes to next screen b goes to previous screen
9 l goes to screen n v goes to current screen
10 s searches until screen n y yank deleted string
11
12 Syntax and implementation style a la PolyFORTH
13 If you don't like it, write a block editor mode for Emacs!
14
15
ok
Creating your own block file
To create your own new block file myblocks.fb
type: use blocked.fb
type: 1 load
type editor
Then
type use myblocks.fb
1 load will show BLOCK #1 (lines 0 till 15. 16 Lines of 64 characters each)
1 t will highlight line 1
Type i this is text to [i]nsert into line 1
After the current BLOCK is edited type flush in order to write BLOCK #1 to the file myblocks.fb
For more information see, gForth Blocks
It turns out these are "Editor Commands" the book says,
For Those Whose EDITOR Doesn't Follow These Rules
The FORTH-79 Standard does not specify editor commands. Your system may use a different editor; if so, check your systems documentation
I don't believe gforth supports an internal editor at all. So L, T, I, P, F, E, D, R are all presumably unsupported.
gforth is well integrated with emacs. In my xemacs here, by default any file called *.fs is considered FORTH source. "C-h m", as usual, gives the available commands.
No, GNU Forth doesn't have an internal editor; I use Vim :)
I am using the interpreter directives (non ANS standard) control structures of Gforth as described in the manual section 5.13.4 Interpreter Directives. I basically want to use the loop words to create a dynamically sized word containing literals. I came up with this definition for example:
: foo
[ 10 ] [FOR]
1
[NEXT]
;
Yet this produces an Address alignment exception after the [FOR] (yes, I know you should not use a for loop in Forth at all. This is just for an easy example).
In the end it turned out that you have to write loops as one-liners in order to ensure their correct execution. So doing
: foo [ 10 [FOR] ] 1 [ [NEXT] ] ;
instead works as intended. Running see foo yields:
: foo
1 1 1 1 1 1 1 1 1 1 1 ; ok
which is exactly what I want.
Is there a way to get new lines in the word definition? The words I would like to write are way more complex, and for a presentation I would need them better formatted.
It would really be best to use an immediate word instead. For example,
: ones ( n -- ) 0 ?do 1 postpone literal loop ; immediate
: foo ( -- ten ones ) [ 10 ] ones ;
With SEE FOO resulting in the same as your example. With POSTPONE, especially with Gforth's ]] .. [[ syntax, the repeated code can be as elaborate as you like.
A multiline [FOR] would need to do four things:
Use REFILL to read in subsequent lines.
Save the read-in lines, because you'll need to evaluate them one by one to preserve line-expecting parsing behavior (such as from comments: \ ).
Stop reading in lines, and loop, when you match the terminating [NEXT].
Take care to leave >IN right after the [NEXT] so that interpretation can continue normally.
You might still run into issues with some code, like code checking SOURCE-ID.
For an example of using REFILL to parse across multiple lines, here's code from a recent posting from CLF, by Gerry:
: line, ( u1 caddr2 u2 -- u3 )
tuck here swap chars dup allot move +
;
: <text> ( "text" -- caddr u )
here 0
begin
refill
while
bl word count s" </text>" compare
while
0 >in ! source line, bl c, 1+
repeat then
;
This collects everything between <text> and a </text> that's on its own line, as with a HERE document, while also adding spaces. To save the individual lines for [FOR] in an easy way, I'd recommend leaving 0 as a sentinel on the data stack and then drop SAVE-MEM 'd lines on top of it.
in a ruby learning book .I face this code :
f = File.new("a.txt", "r")
while a = f.getc
puts a.chr
f.seek(5, IO::SEEK_CUR)
end
author writes that this code produce every fifth character in a file, but I don't understand why? please explain me line by line.
thanks.
f = File.new("a.txt", "r")
This line opens the file in read mode and keeps the file object(as an I/O(Input/Output) stream) in variable f. (See File#new)
while a = f.getc
getc is a method of class IO which gets one character of the I/O stream at a time and it will give nil, when it meets the end of the I/O stream. So while a = f.getc will loop until the end of file. (See IO#getc)
puts a.chr
f.getc will give the ASCII value of the character and inorder to get the character from the ASCII value, we apply a.chr(See Integer#chr). I think in Ruby 1.9, we will get the character itself as the output of getc, but for earlier versions, we get the ASCII value as the output. The first getc command reads the first character and moves the position of I/O stream after the first character.
f.seek(5, IO::SEEK_CUR)
seek is a method of I/O stream which changes the position of the I/O stream by an offset of the first parameter from the second parameter. IO::SEEK_CUR is a constant which gives the current position of the I/O stream. So f.seek(5, IO::SEEK_CUR) moves the position to 5 places from the current position. (See IO#seek)
This will continue till a = f.getc becomes a false condition(here at the end of file, f.getc becomes nil, which is a falsey value in Ruby(false and nil are the only falsy values in Ruby, all others are truth values))
Use IRB to study and experiment with Ruby.
a = f.getc; puts a.chr outputs a single character; f.seek(5, IO::SEEK_CUR) moves forward by 5 characters.
I have a multiple sequence alignment (Clustal) file and I want to read this file and arrange sequences in such a way that it looks more clear and precise in order.
I am doing this from Biopython using an AlignIO object:
alignment = AlignIO.read("opuntia.aln", "clustal")
print "Number of rows: %i" % len(align)
for record in alignment:
print "%s - %s" % (record.id, record.seq)
My output looks messy and long scrolling. What I want to do is print only 50 sequences in each line and continue until the end of the alignment file.
I wish to have output like this, from http://www.ebi.ac.uk/Tools/clustalw2/.
Br,
I don't have biopython on this computer, so this isn't tested, but it should work:
chunk_size = 50
for i in range(0, alignment.get_alignment_length(), chunk_size):
print ""
for record in alignment:
print "%s\t%s %i" % (record.name, record.seq[i:i + chunk_size], i + chunk_size)
Does the same trick as Eli's one - using range to set up an index to slice from then iterating over the record in the alignment for each slice.
Do you require something more complex than simply breaking record.seq into chunks of 50 characters, or am I missing something?
You can use Python sequence slicing to achieve that very easily. seq[N:N+50] accesses the 50 sequence elements starting with N:
In [24]: seq = ''.join(str(random.randint(1, 4)) for i in range(200))
In [25]: seq
Out[25]: '13313211211434211213343311221443122234343421132111223234141322124442112343143112411321431412322123214232414331224144142222323421121312441313314342434231131212124312344112144434314122312143242221323123'
In [26]: for n in range(0, len(seq), 50):
....: print seq[n:n+50]
....:
....:
13313211211434211213343311221443122234343421132111
22323414132212444211234314311241132143141232212321
42324143312241441422223234211213124413133143424342
31131212124312344112144434314122312143242221323123
I want to display the progress of a calculation done with a DO-loop, on the console screen. I can print out the progress variable to the terminal like this:
PROGRAM TextOverWrite_WithLoop
IMPLICIT NONE
INTEGER :: Number, Maximum = 10
DO Number = 1, MAXIMUM
WRITE(*, 100, ADVANCE='NO') REAL(Number)/REAL(Maximum)*100
100 FORMAT(TL10, F10.2)
! Calcultations on Number
END DO
END PROGRAM TextOverWrite_WithLoop
The output of the above code on the console screen is:
10.00 20.00 30.00 40.00 50.00 60.00 70.00 80.00
90.00 100.00
All on the same line, wrapped only by the console window.
The ADVANCE='No' argument and the TL10 (tab left so many spaces) edit descriptor works well to overwrite text on the same line, e.g. the output of the following code:
WRITE(*, 100, ADVANCE='NO') 100, 500
100 FORMAT(I3, 1X, TL4, I3)
Is:
500
Instead of:
100 500
Because of the TL4 edit descriptor.
From these two instances one can conclude that the WRITE statement cannot overwrite what has been written by another WRITE statement or by a previous execution of the same WRITE satement (as in a DO-loop).
Can this be overcome somehow?
I am using the FTN95 compiler on Windows 7 RC1. (The setup program of the G95 compiler bluescreens Windows 7 RC1, even thought it works fine on Vista.)
I know about the question Supressing line breaks in Fortran 95 write statements, but it does not work for me, because the answer to that question means new ouput is added to the previous output on the same line; instead of new output overwriting the previous output.
Thanks in advance.
The following should be portable across systems by use of ACHAR(13) to encode the carriage return.
character*1 creturn
! CODE::
creturn = achar(13) ! generate carriage return
! other code ...
WRITE( * , 101 , ADVANCE='NO' ) creturn , i , npoint
101 FORMAT( a , 'Point number : ',i7,' out of a total of ',i7)
There is no solution to this question within the scope of the Fortran standards. However, if your compiler understand backslash in Fortran strings (GNU Fortran does if you use the option -fbackslash), you can write
write (*,"(A)",advance="no") "foo"
call sleep(1)
write (*,"(A)",advance="no") "\b\b\bbar"
call sleep(1)
write (*,"(A)",advance="no") "\b\b\bgee"
call sleep(1)
write (*,*)
end
This uses the backslash character (\b) to erase previously written characters on that line.
NB: if your compiler does not understand advance="no", you can use related non-standard tricks, such as using the $ specifier in the format string.
The following worked perfectly using g95 fortran:
NF = NF + 1
IF(MOD(NF,5).EQ.0) WRITE(6,42,ADVANCE='NO') NF, ' PDFs'//CHAR(13)
42 FORMAT(I6,A)
gave:
5 PDFs
leaving the cursor at the #1 position on the same line. On the next update,
the 5 turned into a 10. ASCII 13 (decimal) is a carriage return.
OPEN(6,CARRIAGECONTROL ='FORTRAN')
DO I=1,5
WRITE(6,'(1H+" ",I)') I
ENDDO