Discussion:
getFile() --> Open() commands...
(too old to reply)
Lysander
2008-11-11 15:50:39 UTC
Permalink
... but it does not open it to me?
f.open(fn,"R") // R for read only text file, to avoid
How do you know that the file is NOT open?

I think that maybe you misinterpret the use of the f.open() command. It
opens a "stream" of data for you, so that you could now start reading
the contents of the file into - for example - an editorcontrol.

It does _NOT_ open it the "windows"-way, this would be "open to edit".
unknown
2008-11-11 19:17:18 UTC
Permalink
On Tue, 11 Nov 2008 10:34:46 -0500 Ivan Benttini
Sender: "Ivan Benttini" <***@nc.rr.com>
wrote the following in:
Newsgroup: dbase.programming
Dear people,
What am I doing wrong here, since I can seletect the file I want without any
error, but it does not open it to me?
Thanks in advance for any help.
Ivan
You need to explain more clearly what you intend to do. I have assumed that you said:

"I want to select a text file using the getFile function, and then print the selected text file to
the results pane"

Save and run the code below my signature to see one way to do it. When the Dialog box opens, select
the file License.txt.
f.open(fn,"R") // R for read only text file, to avoid
changes to be made.
This is a misunderstanding. The "R" does mot mean 'Read only". Look up the OLH on 'File class' to
see the correct meaning.


Ivar B. Jessen

//-----
clear

fileName = getFile(_dbwinhome + "*.txt", "Chose text File",TRUE)
? openTextFile(Filename)
?

function openTextFile(cFile)
********************************

if empty(cFile)
return null
endif

f = new file()
f.open(cFile, "R")
cStr = f.read(250) // Read 250 character, just to demonstrate that the code works
f.close()

return cStr
//-----
Roland Wingerter
2008-11-12 00:09:09 UTC
Permalink
Ivar B. Jessen WROTE
Post by unknown
"I want to select a text file using the getFile function, and then print
the selected text file to
the results pane"
---------
Or perhaps Ivan wants to show the contents of that file using a programme
associated with the *.txt extension?

//-----
clear
set procedure to :dUFLP:miscapi.prg
fileName = getFile("*.txt", "Choose text File",TRUE)

? openURL(Filename)
//-----

Roland
Ivan Benttini
2008-11-12 03:39:53 UTC
Permalink
Hi Roland,
My name is Ivan Benttini.
Thanks for join in helping me.
In my form menu under FILE it drops down NEW-OPEN-CLOSE-PRINT.
My goal at the end of the first menu entry which is FILE, is to be able to
Open
a window like dialog box, choose from the root C:\, a directory, a folder
and then
a file, in a format(i guess .txt) that I can print it in a chosen printer.
Of course to me this is a very tall order, since I don't know much, but I
will get
there, came rain or hot water(in dBase+ everything is possible) not for me
yet,
but I will get there.One thing has nothing to do with another, but because
of dBase
learning curve being so big for me, I already learn HTML to the point of
make few
dollars, when I wait for help from this life line to me (dbase Programming
user's group)
So, now you know, and so many THANKS to you for join in making me a better
programmer.
With help from some these wonderful people(the user'sgroup), I now can open,
choose
and I am in the process of learn to print. That is where I stuck now.
I can only print one page of a seleced document, and that is after I close
the form and then
dBase+(2.5). Soon I may be able to afford the 2.6 version.
If you don't mind and have the time to help me, I will send you my menu code
function that
deals with the first entry(FILE). I am writting an application. Hope some
day I will have
a CD (with the help of the INNO I hope) with it to install in a virgen
machine w/o dBASE,
so that it can run, just like any other windows application.
Ivan
PS: I am going to try your recomendation tomorrow OK. I am very tired now.
Post by Roland Wingerter
Ivar B. Jessen WROTE
Post by unknown
"I want to select a text file using the getFile function, and then print
the selected text file to
the results pane"
---------
Or perhaps Ivan wants to show the contents of that file using a programme
associated with the *.txt extension?
//-----
clear
set procedure to :dUFLP:miscapi.prg
fileName = getFile("*.txt", "Choose text File",TRUE)
? openURL(Filename)
//-----
Roland
Ivan Benttini
2008-11-11 22:21:51 UTC
Permalink
Thanks Ivar,
Is there a simple way to see it on the screen, like I see it in the command
window that you can share with me?
I send the same message to Mervyn and Andre who also help me.
So if you see the tread please do not get me incorrect, I am just gratefull
to everyone's time.
Once my father told me "nothing is more important to give to someone them
your time to help them"
I live by it.
Ivan
Post by unknown
On Tue, 11 Nov 2008 10:34:46 -0500 Ivan Benttini
Newsgroup: dbase.programming
Dear people,
What am I doing wrong here, since I can seletect the file I want without any
error, but it does not open it to me?
Thanks in advance for any help.
Ivan
"I want to select a text file using the getFile function, and then print
the selected text file to
the results pane"
Save and run the code below my signature to see one way to do it. When the
Dialog box opens, select
the file License.txt.
f.open(fn,"R") // R for read only text file, to avoid
changes to be made.
This is a misunderstanding. The "R" does mot mean 'Read only". Look up the
OLH on 'File class' to
see the correct meaning.
Ivar B. Jessen
//-----
clear
fileName = getFile(_dbwinhome + "*.txt", "Chose text File",TRUE)
? openTextFile(Filename)
?
function openTextFile(cFile)
********************************
if empty(cFile)
return null
endif
f = new file()
f.open(cFile, "R")
cStr = f.read(250) // Read 250 character, just to demonstrate that the code works
f.close()
return cStr
//-----
Ivan Benttini
2008-11-12 17:37:23 UTC
Permalink
Ivar,
You did a very good job, Yes indeed, just one small problem
I some how did not print anything(the file I selected), maybe some in the
code
perhaps? ( the printer attach to my computer is ON.)
It got to be some small thing somewhere in all that fancy code.
Thank you so much, your idea is great.
Ivan
On Tue, 11 Nov 2008 17:21:51 -0500 Ivan Benttini
Newsgroup: dbase.programming
Post by Ivan Benttini
Thanks Ivar,
Is there a simple way to see it on the screen, like I see it in the command
window that you can share with me?
Save the code below my signature as indicated and run.
Is this what you have in mind?
Ivar B. Jessen
//----- Save as getTextFile.wfm -----
** END HEADER -- do not remove this line
//
// Generated on 12-11-2008
//
parameter bModal
local f
f = new getTextFileForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class getTextFileForm of FORM
with (this)
height = 13.5
left = 43.5714
top = 1.1818
width = 66.2857
text = ""
endwith
this.EDITOR1 = new EDITOR(this)
with (this.EDITOR1)
height = 9.5
left = 4.0
top = 1.0
width = 59.0
value = ""
endwith
this.GETFILE = new PUSHBUTTON(this)
with (this.GETFILE)
onClick = class::GETFILE_ONCLICK
height = 1.0909
left = 4.0
top = 11.5
width = 15.2857
text = "Get textfile"
endwith
this.PRINTFILE = new PUSHBUTTON(this)
with (this.PRINTFILE)
onClick = class::PRINTFILE_ONCLICK
height = 1.0909
left = 21.0
top = 11.5
width = 15.2857
text = "Print"
endwith
function GETFILE_onClick
form.editor1.value = ""
form.fileName = getFile(_dbwinhome + "*.txt", "Chose text File",TRUE)
if empty(form.fileName)
return null
endif
f = new file()
f.open(form.fileName, "R")
form.cStr = f.read(f.size(form.fileName))
f.close()
form.editor1.value = form.cStr
return
function PRINTFILE_onClick
#include Winuser.h
#define WINAPI_A "A"
#define WINAPI_SHELL "SHELL32"
extern cHandle ShellExecute( cHandle, cString, cString, ;
cString, cString, cINT ) WINAPI_SHELL ;
from "ShellExecute" + WINAPI_A
_app.printer.chooseprinter()
ShellExecute(_app.Framewin.hwnd, "print", ;
form.filename, null, null, SW_HIDE)
return
endclass
//-----
Ivan Benttini
2008-11-12 19:36:33 UTC
Permalink
Yes I did, and it did work totally.
I am sorry maybe I was not clear in my previous email.
Some times I think I am right in my questions to the group, but I gess I am
not, sorry.
Some times I get so excide about seing some happens, I junp to something
else.
I will try to be more controled.
Many thanks for your help as always.
Ivan
On Wed, 12 Nov 2008 12:37:23 -0500 Ivan Benttini
Newsgroup: dbase.programming
Post by Ivan Benttini
Ivar,
You did a very good job, Yes indeed, just one small problem
I some how did not print anything(the file I selected), maybe some in the
code
perhaps? ( the printer attach to my computer is ON.)
It got to be some small thing somewhere in all that fancy code.
Ivan,
If you want some help you need to be much more specific. Nobody wants to
spend their time in trying
to guess what file you selected :-)
Did you actually run the form as posted and select the file License.txt?
What was the result?
Ivar B. Jessen
unknown
2008-11-12 18:46:23 UTC
Permalink
On Wed, 12 Nov 2008 12:37:23 -0500 Ivan Benttini
Sender: "Ivan Benttini" <***@nc.rr.com>
wrote the following in:
Newsgroup: dbase.programming
Post by Ivan Benttini
Ivar,
You did a very good job, Yes indeed, just one small problem
I some how did not print anything(the file I selected), maybe some in the
code
perhaps? ( the printer attach to my computer is ON.)
It got to be some small thing somewhere in all that fancy code.
Ivan,

If you want some help you need to be much more specific. Nobody wants to spend their time in trying
to guess what file you selected :-)

Did you actually run the form as posted and select the file License.txt? What was the result?


Ivar B. Jessen
unknown
2008-11-12 15:59:57 UTC
Permalink
On Tue, 11 Nov 2008 17:21:51 -0500 Ivan Benttini
Sender: "Ivan Benttini" <***@nc.rr.com>
wrote the following in:
Newsgroup: dbase.programming
Post by Ivan Benttini
Thanks Ivar,
Is there a simple way to see it on the screen, like I see it in the command
window that you can share with me?
Save the code below my signature as indicated and run.

Is this what you have in mind?


Ivar B. Jessen

//----- Save as getTextFile.wfm -----

** END HEADER -- do not remove this line
//
// Generated on 12-11-2008
//
parameter bModal
local f
f = new getTextFileForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class getTextFileForm of FORM
with (this)
height = 13.5
left = 43.5714
top = 1.1818
width = 66.2857
text = ""
endwith

this.EDITOR1 = new EDITOR(this)
with (this.EDITOR1)
height = 9.5
left = 4.0
top = 1.0
width = 59.0
value = ""
endwith

this.GETFILE = new PUSHBUTTON(this)
with (this.GETFILE)
onClick = class::GETFILE_ONCLICK
height = 1.0909
left = 4.0
top = 11.5
width = 15.2857
text = "Get textfile"
endwith

this.PRINTFILE = new PUSHBUTTON(this)
with (this.PRINTFILE)
onClick = class::PRINTFILE_ONCLICK
height = 1.0909
left = 21.0
top = 11.5
width = 15.2857
text = "Print"
endwith


function GETFILE_onClick

form.editor1.value = ""
form.fileName = getFile(_dbwinhome + "*.txt", "Chose text File",TRUE)
if empty(form.fileName)
return null
endif

f = new file()
f.open(form.fileName, "R")
form.cStr = f.read(f.size(form.fileName))
f.close()
form.editor1.value = form.cStr

return

function PRINTFILE_onClick

#include Winuser.h
#define WINAPI_A "A"
#define WINAPI_SHELL "SHELL32"

extern cHandle ShellExecute( cHandle, cString, cString, ;
cString, cString, cINT ) WINAPI_SHELL ;
from "ShellExecute" + WINAPI_A

_app.printer.chooseprinter()

ShellExecute(_app.Framewin.hwnd, "print", ;
form.filename, null, null, SW_HIDE)

return
endclass
//-----
Ivan Benttini
2008-11-12 18:06:53 UTC
Permalink
Hi, Ivar

I am sorry, It did print only .TXT files, but when I try to print the code
of another document
like .WFM is when it did not print (my previous email). Is that because you
code specify only to
take care of .TXT files?

Can we print anything selected by change it to [ *.* ], instead of [
*.TXT ], maybe?
************************************************************************
***** form.fileName = getFile(_dbwinhome + "*.txt", "Chose text File",TRUE)
***********
********************************* "*.*"
******************************

Please understand, I am not try to correct you at all, but will be nice for
me to be able to print any file.
What you think? specially now that you got it down pack.
I will not touch anything without your permission and your reply.
Millie gracie, (thanks very much)
Ivan
On Tue, 11 Nov 2008 17:21:51 -0500 Ivan Benttini
Newsgroup: dbase.programming
Post by Ivan Benttini
Thanks Ivar,
Is there a simple way to see it on the screen, like I see it in the command
window that you can share with me?
Save the code below my signature as indicated and run.
Is this what you have in mind?
Ivar B. Jessen
//----- Save as getTextFile.wfm -----
** END HEADER -- do not remove this line
//
// Generated on 12-11-2008
//
parameter bModal
local f
f = new getTextFileForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class getTextFileForm of FORM
with (this)
height = 13.5
left = 43.5714
top = 1.1818
width = 66.2857
text = ""
endwith
this.EDITOR1 = new EDITOR(this)
with (this.EDITOR1)
height = 9.5
left = 4.0
top = 1.0
width = 59.0
value = ""
endwith
this.GETFILE = new PUSHBUTTON(this)
with (this.GETFILE)
onClick = class::GETFILE_ONCLICK
height = 1.0909
left = 4.0
top = 11.5
width = 15.2857
text = "Get textfile"
endwith
this.PRINTFILE = new PUSHBUTTON(this)
with (this.PRINTFILE)
onClick = class::PRINTFILE_ONCLICK
height = 1.0909
left = 21.0
top = 11.5
width = 15.2857
text = "Print"
endwith
function GETFILE_onClick
form.editor1.value = ""
form.fileName = getFile(_dbwinhome + "*.txt", "Chose text File",TRUE)
if empty(form.fileName)
return null
endif
f = new file()
f.open(form.fileName, "R")
form.cStr = f.read(f.size(form.fileName))
f.close()
form.editor1.value = form.cStr
return
function PRINTFILE_onClick
#include Winuser.h
#define WINAPI_A "A"
#define WINAPI_SHELL "SHELL32"
extern cHandle ShellExecute( cHandle, cString, cString, ;
cString, cString, cINT ) WINAPI_SHELL ;
from "ShellExecute" + WINAPI_A
_app.printer.chooseprinter()
ShellExecute(_app.Framewin.hwnd, "print", ;
form.filename, null, null, SW_HIDE)
return
endclass
//-----
Mervyn Bick
2008-11-12 19:51:04 UTC
Permalink
function PRINTFILE_onClick
#include Winuser.h
#define WINAPI_A "A"
#define WINAPI_SHELL "SHELL32"
extern cHandle ShellExecute( cHandle, cString, cString, ;
cString, cString, cINT ) WINAPI_SHELL ;
from "ShellExecute" + WINAPI_A
_app.printer.chooseprinter()
ShellExecute(_app.Framewin.hwnd, "print", ;
form.filename, null, null, SW_HIDE)
return
Ivar,

The chooseprinter() gave me a choice but the program didn't recognise the
selection and printed the file to my default printer.

Mervyn.
unknown
2008-11-13 09:50:16 UTC
Permalink
On Wed, 12 Nov 2008 21:51:04 +0200 Mervyn Bick
Sender: "Mervyn Bick" <invalid.invalid.invalid>
wrote the following in:
Newsgroup: dbase.programming
Post by Mervyn Bick
function PRINTFILE_onClick
[snip]
Post by Mervyn Bick
return
Ivar,
The chooseprinter() gave me a choice but the program didn't recognise the
selection and printed the file to my default printer.
It looks like ShellExecute prints to the printer which is set to be the Standard printer, probably
the one that in _app.printer.printer has the number 1, corresponding to 'Windows default'. See OLH
on 'printerSource'.

There must be a better way to print a text file, any ideas?


Ivar B. Jessen

Mervyn Bick
2008-11-11 19:00:50 UTC
Permalink
Dear people,
What am I doing wrong here, since I can seletect the file I want without
any
error, but it does not open it to me?
Thanks in advance for any help.
Ivan
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE) //, ".*")
//this line works
?fileName
//this line works, it shows in command window
// the name of the file I selected
#define fn "fileName" // here I would like the name of the .txt
The line above is not necessary. The name of the file you want is already
in the variable fileName as you have already proven with ? fileName.
#define creates a constant rather than a variable and is more suited for
when one wants to "hard code" a name into a program. In your case you are
using getfile() to select a file from many and you have no idea of which
one will be chosen so you can't hard code the name.
file I select above w/the GETFILE().
f=new file() // I also try putting &(macro
substitute) ---- ("&fileName") like that,
if f.exists(fn) // but at no avail.
f.open(fn,"R") // R for read only text file, to avoid
changes to be made.
else
//f.create(fn,"R")
endif
//f.puts(new date().toLocaleString())//
//f.close()//
return
In the code above you can't use "R" to make the file read only because
further down you are going to write the date to the file. This is
probably why nothing appears to be happening. This is fine when you hard
code a test file name but rather dangerous with getfile() where you might
select something important by mistake. Instead of writing the date to the
file, print the file to the command pane to see that this is working.
Seeing that you are selecting a file with getfile() it must exist so it is
pointless checking with exists(). The check is important if you are, say,
writing a log file. open() can only work with an existing file. If it's
not there it has to be made with create().

function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE)
f = new File()
f.open(fileName, "R") // Here we can use "R" as we are not writing
to the file
do while not f.eof( ) // Pick a SHORT file. <g>
? f.gets( )
enddo
f.close()
return


Mervyn.
Ivan Benttini
2008-11-11 22:19:59 UTC
Permalink
Thank you Mervyn,
Is there a simple way to see it on the screen, like I see it in the command
window that you can share with me?
I send the same message to Ivar and Andre who also help me.
So if you see the tread please do not get me incorrect, I am just gratefull
to everyone's time.
Once my father told me "nothing is more important to give to someone them
your time to help them"
I live by it.
Ivan
Post by Mervyn Bick
Dear people,
What am I doing wrong here, since I can seletect the file I want without
any
error, but it does not open it to me?
Thanks in advance for any help.
Ivan
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE) //, ".*")
//this line works
?fileName
//this line works, it shows in command window
// the name of the file I selected
#define fn "fileName" // here I would like the name of the .txt
The line above is not necessary. The name of the file you want is already
in the variable fileName as you have already proven with ? fileName.
#define creates a constant rather than a variable and is more suited for
when one wants to "hard code" a name into a program. In your case you are
using getfile() to select a file from many and you have no idea of which
one will be chosen so you can't hard code the name.
file I select above w/the GETFILE().
f=new file() // I also try putting &(macro
substitute) ---- ("&fileName") like that,
if f.exists(fn) // but at no avail.
f.open(fn,"R") // R for read only text file, to avoid
changes to be made.
else
//f.create(fn,"R")
endif
//f.puts(new date().toLocaleString())//
//f.close()//
return
In the code above you can't use "R" to make the file read only because
further down you are going to write the date to the file. This is
probably why nothing appears to be happening. This is fine when you hard
code a test file name but rather dangerous with getfile() where you might
select something important by mistake. Instead of writing the date to the
file, print the file to the command pane to see that this is working.
Seeing that you are selecting a file with getfile() it must exist so it is
pointless checking with exists(). The check is important if you are, say,
writing a log file. open() can only work with an existing file. If it's
not there it has to be made with create().
function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE)
f = new File()
f.open(fileName, "R") // Here we can use "R" as we are not writing
to the file
do while not f.eof( ) // Pick a SHORT file. <g>
? f.gets( )
enddo
f.close()
return
Mervyn.
Mervyn Bick
2008-11-12 06:17:53 UTC
Permalink
Post by Ivan Benttini
Mervyn,
Please look at this function code and help me in understand why I can
only
print one page
of a selected document and only after I close the form and dbase!
My goal is to print the selected document when I am using the form.
If you're going to print in dBase Plus you should get to grips with the
report writer. Using SET PRINT ON...?...SET PRINT OFF dates back to dBase
for DOS and isn't really suited to Windows. I tried your code and
although it wouldn't start printing untill I closed dBase, the entire file
did print. (I ignored my own advice and picked a LONG file. <g>)
chooseprinter also had no effect.

Roland's sugggestion of using openurl() from miscapi.prg is a good way to
go if you can accept the browser window that opens. You can view the file
and then print if needed using the browser menu. This allows one to
select a printer so the code in your program is very simple.

First, try to run miscapi.prg in the dUFLP. You will get a message that
the program is not meant to be run. Ignore this but this step is needed
to create miscapi.pro which is needed before you can use set procedure
to..... (The notes that are in miscapi.prg suggest copying the functions
as needed and pasting them into your code. If you go this route then
openurl(filename) in the code below must be class::openurl(filename)

In your form's onOpen event add set procedure to :DUFLP:miscapi.prg
additive (Additive is apparently no longer necessary if you are using
the latest version of dBase but it can't do any harm.)



function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE)
openurl(filename)
return


Mervyn.
Ivan Benttini
2008-11-12 15:28:47 UTC
Permalink
Mervyn,
You are very correct. I have try and it works to every one satisfaction.
Thanks, for the teaching. It seams that this marvel [ miscapi.prg ] has a
lots
of help on it's on. I will start using it more, although some of the code I
do no
understand for now.
Have a good one friend,
Ivan
Post by Mervyn Bick
Post by Ivan Benttini
Mervyn,
Please look at this function code and help me in understand why I can only
print one page
of a selected document and only after I close the form and dbase!
My goal is to print the selected document when I am using the form.
If you're going to print in dBase Plus you should get to grips with the
report writer. Using SET PRINT ON...?...SET PRINT OFF dates back to dBase
for DOS and isn't really suited to Windows. I tried your code and
although it wouldn't start printing untill I closed dBase, the entire file
did print. (I ignored my own advice and picked a LONG file. <g>)
chooseprinter also had no effect.
Roland's sugggestion of using openurl() from miscapi.prg is a good way to
go if you can accept the browser window that opens. You can view the file
and then print if needed using the browser menu. This allows one to
select a printer so the code in your program is very simple.
First, try to run miscapi.prg in the dUFLP. You will get a message that
the program is not meant to be run. Ignore this but this step is needed
to create miscapi.pro which is needed before you can use set procedure
to..... (The notes that are in miscapi.prg suggest copying the functions
as needed and pasting them into your code. If you go this route then
openurl(filename) in the code below must be class::openurl(filename)
In your form's onOpen event add set procedure to :DUFLP:miscapi.prg
additive (Additive is apparently no longer necessary if you are using
the latest version of dBase but it can't do any harm.)
function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE)
openurl(filename)
return
Mervyn.
Marilyn Price
2008-11-12 13:12:50 UTC
Permalink
Post by Ivan Benttini
Mervyn,
Please look at this function code and help me in understand why I can only
print one page
of a selected document and only after I close the form and dbase!
With Windows, you have to add the line I inserted below. However,
Mervyn is correct - get comfortable with the Report Writer - it will
serve you better in the long run.
Post by Ivan Benttini
fnction MENU10_onClick //chose printer to output a hard copy
choosePrinter()
/*
Here open a dialog box and choose some to printer
on the selected printer.
*/
CLEAR //this clear the dBASE+ command window.
set printer ON
fileName=getFile("*.txt", "Chose text File",TRUE)
f = new File()
f.open(fileName, "R") // Here we can use "R" as we are not writing
// to the file
do while not f.eof( )// Pick a SHORT file. <g>
? f.gets( )
enddo
f.close()
set printer OFF
close printer
Post by Ivan Benttini
return
--
Marilyn Price
M. P. Data
Ivan Benttini
2008-11-12 02:46:12 UTC
Permalink
Mervyn,
Please look at this function code and help me in understand why I can only
print one page
of a selected document and only after I close the form and dbase!
My goal is to print the selected document when I am using the form.
Thank you friend,
Ivan

fnction MENU10_onClick //chose printer to output a hard copy
choosePrinter()
/*
Here open a dialog box and choose some to printer
on the selected printer.
*/
CLEAR //this clear the dBASE+ command window.
set printer ON
fileName=getFile("*.txt", "Chose text File",TRUE)
f = new File()
f.open(fileName, "R") // Here we can use "R" as we are not writing
// to the file
do while not f.eof( )// Pick a SHORT file. <g>
? f.gets( )
enddo
f.close()
set printer OFF
return
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Post by Mervyn Bick
Dear people,
What am I doing wrong here, since I can seletect the file I want without
any
error, but it does not open it to me?
Thanks in advance for any help.
Ivan
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE) //, ".*")
//this line works
?fileName
//this line works, it shows in command window
// the name of the file I selected
#define fn "fileName" // here I would like the name of the .txt
The line above is not necessary. The name of the file you want is already
in the variable fileName as you have already proven with ? fileName.
#define creates a constant rather than a variable and is more suited for
when one wants to "hard code" a name into a program. In your case you are
using getfile() to select a file from many and you have no idea of which
one will be chosen so you can't hard code the name.
file I select above w/the GETFILE().
f=new file() // I also try putting &(macro
substitute) ---- ("&fileName") like that,
if f.exists(fn) // but at no avail.
f.open(fn,"R") // R for read only text file, to avoid
changes to be made.
else
//f.create(fn,"R")
endif
//f.puts(new date().toLocaleString())//
//f.close()//
return
In the code above you can't use "R" to make the file read only because
further down you are going to write the date to the file. This is
probably why nothing appears to be happening. This is fine when you hard
code a test file name but rather dangerous with getfile() where you might
select something important by mistake. Instead of writing the date to the
file, print the file to the command pane to see that this is working.
Seeing that you are selecting a file with getfile() it must exist so it is
pointless checking with exists(). The check is important if you are, say,
writing a log file. open() can only work with an existing file. If it's
not there it has to be made with create().
function MENU8_onClick //OPEN dialog window to select file to open
fileName=getFile("*.txt", "Chose text File",TRUE)
f = new File()
f.open(fileName, "R") // Here we can use "R" as we are not writing
to the file
do while not f.eof( ) // Pick a SHORT file. <g>
? f.gets( )
enddo
f.close()
return
Mervyn.
Ivan Benttini
2008-11-11 17:22:24 UTC
Permalink
I don't think the file is open because, I am in an isolate computer (not in
a network of any kind)
in my house, and I know where I have the text file (c:\AB\xyz.txt) and I did
not open it, before I open my form that
deals with it.
I don't know much, but I do see it in the command window, and I thought the
OPEN() command
would open it for me to read.
Since my code is not opening the text file I selected, can you help me by
correct my code
to do that.
As always, many thanks in advance,
Ivan
Post by Lysander
... but it does not open it to me?
f.open(fn,"R") // R for read only text file, to avoid
How do you know that the file is NOT open?
I think that maybe you misinterpret the use of the f.open() command. It
opens a "stream" of data for you, so that you could now start reading the
contents of the file into - for example - an editorcontrol.
It does _NOT_ open it the "windows"-way, this would be "open to edit".
Ivan Benttini
2008-11-11 22:13:05 UTC
Permalink
Thank you Andre
Mille gracie.
Ivan
Post by Lysander
... but it does not open it to me?
f.open(fn,"R") // R for read only text file, to avoid
How do you know that the file is NOT open?
I think that maybe you misinterpret the use of the f.open() command. It
opens a "stream" of data for you, so that you could now start reading the
contents of the file into - for example - an editorcontrol.
It does _NOT_ open it the "windows"-way, this would be "open to edit".
Loading...