1. Question about print,puts,get,gets,...
- Posted by Frank <sekret7 at hotmail.com> Jun 10, 2001
- 382 views
Hello I need help. I am new to Euphoria or any other programing language. For start I was learning how to devenlope a diferent kind of windows in Windows mode. Now I am trying to learn how to open-close file, type of variable, work with different kind of data. Here is my problem: 1.I want to enter text data to EditText control in window. 2.Get it from control and put it to file.dat as part of sequence. {"Tim","Mary","David",...} If I look file.dat I wish to see it as writen above. Close file.dat. 3.Get the data from file.dat as sequence, becouse I will need seq[1] or seq[2],... to be writen in window. I try to do the program my self, but even after the looking at examples I am confuesd with use of print,puts,get,gets and any similar routines. Best regards and thans, Frank Black
2. Re: Question about print,puts,get,gets,...
- Posted by david at aldred.demon.co.uk Jun 11, 2001
- 382 views
In message <0.1700008810.705892030-212058698-992210473 at topica.com>, Frank <sekret7 at hotmail.com> writes >I need help. I am new to Euphoria or any other programing language. >For start I was learning how to devenlope a diferent kind of windows >in Windows mode. Now I am trying to learn how to open-close file, >type of variable, work with different kind of data. > >Here is my problem: Here are some answers! (NB: I haven't tested exactly what's given below). >1.I want to enter text data to EditText control in window. If you want your program to enter the text, then you need to use setText (EditText, "Your Text") (Assuming EditText is the name of your control). >2.Get it from control and put it to file.dat as part of sequence. > {"Tim","Mary","David",...} To get what is in the EditText control, use MyString = getText (EditText) where MyString has been declared as a sequence. Then you need to put MyString into a sequence. If you have three of them, you can do this simply by saying: seq = {MyString1, MyString2, MyString3} To write this to a file, open the file using fn = open ("Filename","w") then print the Euphoria sequence to the file using: print (fn, seq) then close the file: close (fn) >If I look file.dat I wish to see it as writen above. Actually, you won't. You'll see it written in a series of character codes separated by commas and braces. If you really want it legible outside Euphoria, you'll probably need to use printf (fn,"{\"%s\",\"%s,\",\"%s\"}", {MyString1,MyString2,MyString3}) instead of that print statement above: what that is doing is outputting a {, followed by a " and the first string, followed by "," then the next string, and so on, finishing off with a }. Unless you actually need to be able to read the file outside Euphoria, this approach is messier and less flexible: you have to know the number of items in the sequence, for example, which isn't always the case. >3.Get the data from file.dat as sequence, becouse I will need >seq[1] or seq[2],... to be writen in window. Open the file for reading fn = open ("Filename","r") ..then use 'get' to get the sequence: result = get(fn) ..if it worked, then result[1] will be equal to GET_SUCCESS, and result[2] will contain your sequence: if result[1] = GET_SUCCESS then seq = result[2] end if ..then close the file... close (fn) Hope this helps, -- ------------------ ------------------------- |\avid Aldred / David at aldred.demon.co.uk \ Nottingham, England |/ --------------------------------
3. Re: Question about print,puts,get,gets,...
- Posted by martin.stachon at worldonline.cz Jun 13, 2001
- 389 views
----- Original Message ----- From: <david at aldred.demon.co.uk> Subject: Re: Question about print,puts,get,gets,... > >2.Get it from control and put it to file.dat as part of sequence. > > {"Tim","Mary","David",...} > > > Then you need to put MyString into a sequence. If you have three of > them, you can do this simply by saying: > > seq = {MyString1, MyString2, MyString3} > > >If I look file.dat I wish to see it as writen above. > > Actually, you won't. You'll see it written in a series of character > codes separated by commas and braces. If you really want it legible > outside Euphoria, you'll probably need to use > > printf (fn,"{\"%s\",\"%s,\",\"%s\"}", > {MyString1,MyString2,MyString3}) You can use this code : include misc.e type string(sequence s) for i=1 to length(s) do if not atom(s[i]) then return 0 end if end for return 1 end type global function string_print(object x) sequence s if atom(x) then return sprintf("%.10g", x) elsif string(x) then return '"' & x & '"' else s = "{" for i = 1 to length(x) do s &= string_print(x[i]) if i < length(x) then s &= ',' end if end for s &= "}" return s end if end function sequence test test = {"Hello", "World", { "Nested", "seqeunce" } ,1,2,3 , {1,2,3}} puts(1,string_print(test)) However, the code cannot recognize if some sequence could be a string {1,2,3} but you don't want it to be printed as string, because there is no difference between strings and sequences in EU. Regards, Martin