1. Irv: Re: For loop and a newbie
- Posted by jc at cknet.net Mar 26, 2001
- 406 views
Hello Irv > but I'm curious why you > are using atom(vcommands[1])? > The command line parameters are _always_ strings, so, even if > you type "ex myprog One 2 Three 4", each item is a string. Ignorance plain and simple. This simple little routine has produced a significant amount of frustration, trying to learn EU and get this thing to work. I was under the impression that an atom was an individual number, I was thinking that this would test and see if a given parameter was a number or a 'string'. I'm simply trying to get the command line parameters and make sure they are numbers (ascii codes) in a range of 0 to 255. After I check them out I'm going to send them to the printer. This little routine (that I'd written years ago in pascal) is to send control codes to printers or cash drawers. Believe it or not, people pay me money to program in another environment, but I'm feeling like less than a rank beginner! What I think I want are simple chr() and asc() functions. I guess it's back to the drawing board on this 'sequence, atom, integer' business. Thanks for your help Jim Chapman
2. Irv: Re: For loop and a newbie
- Posted by Michael Sabal <mikes at notations.com> Mar 26, 2001
- 457 views
I've been doing this like this quite a bit lately. You're looking for a = chr() routine, but in Euphoria, we don't need one. The asc() routine is a = little more difficult, but Irv's example with value() will fill in nicely. For the moment, we'll assume your device is connected to LPT1: in a DOS = environment. All file pointers are atoms, so we'd open it for writing = using 2 lines of code, and a little error-checking: atom fp fp =3D open ("lpt1:","wb") -- If we're sending control codes,=20 -- it's better to us binary. if fp =3D -1 then abort(1) end if -- a file pointer of -1 indicates an = error. I'm going to use HP PCL5 control codes to demonstrate printing a 10x10 = black box at coordinate (100,100) on the paper: puts(fp,27&"*p100x100Y"&27&"*c10a10b0P") The ampersand (&) in Euphoria is for concatenation. Since every ASCII character is simply a number from 0 to 255, and a string is just an = array (i.e., sequence) of numbers; we just have to concatenate the = non-readable numbers to the string of readable numbers. I could have done = the same line a little lengthier using an intermediate sequence: constant RAWDATA =3D {27,"*p100x100Y",27,"*c10a10b0P"} -- I'm using a constant for demo, but this could just as easily come -- from the command line or a data file. sequence printstring printstring =3D "" -- No variable is pre-initialized in Euphoria. for ctr =3D 1 to length(RAWDATA) do -- except for-loop variables. printstring &=3D RAWDATA[ctr] end for puts(fp,printstring) -- I assume fp has been opened elsewhere=20 -- in the program. Also, don't forget to close any buffered data streams before you end your = program. Most spooled or queued printers won't print a single byte until = the stream is closed: close(fp) Hopefully this will answer a few of your questions. Michael J. Sabal >>> jc at cknet.net 03/26/01 11:21AM >>> This little routine (that I'd written years ago in pascal) is to send = control codes to printers or cash drawers.
3. Re: Irv: Re: For loop and a newbie
- Posted by Irv Mullins <irvm at ellijay.com> Mar 26, 2001
- 434 views
On Mon, 26 Mar 2001, jc at cknet.net wrote: > Hello Irv > > > but I'm curious why you > > are using atom(vcommands[1])? > > The command line parameters are _always_ strings, so, even if > > you type "ex myprog One 2 Three 4", each item is a string. > > Ignorance plain and simple. This simple little routine has produced a > significant amount of frustration, trying to learn EU and get this thing to > work. I was under the impression that an atom was an individual number, An atom _is_ an individual number. However, the parameters input via the command line are not numbers at all, but an "array" of space delimited strings. > I was thinking that this would test and see if a given parameter was a number > or a 'string'. I'm simply trying to get the command line parameters and make > sure they are numbers (ascii codes) in a range of 0 to 255. After I check > them out I'm going to send them to the printer. This little routine (that > I'd written years ago in pascal) is to send control codes to printers or > cash drawers. Believe it or not, people pay me money to program in another > environment, but I'm feeling like less than a rank beginner! What I think I > want are simple chr() and asc() functions. I guess it's back to the drawing > board on this 'sequence, atom, integer' business. Here's a routine to validate and translate numbers: include get.e object x x = command_line() for i = 3 to length(x) do x[i] = value(x[i]) if x[i][1] = 1 then printf(1,"Error: parameter %d must be a number.\n",i) else x[i] = x[i][2] end if end for You will end up with x as a sequence containing: "exu","prgname",n1,n2,n3,n4...... up to however many params were entered. n1... etc _are_ now atoms. If you need a set number of params, then just check the length of the command line first - don't forget to account for the first two "automatic" params: x = command_line() if length(x) < 5 then puts(1,"Need 3 parameters!") end if -- Regards, Irv
4. Re: Irv: Re: For loop and a newbie
- Posted by Kat <gertie at PELL.NET> Mar 26, 2001
- 420 views
On 26 Mar 2001, at 8:21, jc at cknet.net wrote: > Ignorance plain and simple. This simple little routine has produced a > significant amount of frustration, trying to learn EU and get this thing to > work. I was under the impression that an atom was an individual number, I was > thinking that this would test and see if a given parameter was a number or a > 'string'. I'm simply trying to get the command line parameters and make sure > they are numbers (ascii codes) in a range of 0 to 255. After I check them out > I'm going to send them to the printer. This little routine (that I'd written > years ago in pascal) is to send control codes to printers or cash drawers. > Believe it or not, people pay me money to program in another environment, but > I'm feeling like less than a rank beginner! What I think I want are simple > chr() > and asc() functions. I guess it's back to the drawing board on this 'sequence, > atom, integer' business. I think you are confusing "number" and "character" (english words) with "byte" (a machine term). Chances are, you will save yourself some grief if you declare everything to be a sequence or integer. I did pascal programming for years too, and Eu solved a number of problems i had with pascal. Since Eu is so LISPy, it also made some interesting problems. Kat