Discussions related to Visual Prolog
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Read from an external file.

Unread post by ahmednadi »

Dear Sirs;
Could you help me?
How can I capture the content of doc file and put it on a text control box.
Regards;
Ahmed Nady
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi,

:idea: Make a search of "DDE" in this forum.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Read from an external file.

Unread post by Thomas Linder Puls »

ahmednadi wrote:How can I capture the content of doc file ...
Do you mean a Microsoft Word document?
Regards Thomas Linder Puls
PDC
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

Dear Sir;
Thank you for your reply.
yes, sir Microsoft word.
How can I access an external file in MS word and open it to copy its contents to my program in Visual Prolog.
Best regards;
AHMED NADY
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Ahmednadi,

Can you give more specifics ...

Will your application require an installed version of Word, or do you want to read the file directly without using MS Word?

Do you want ALL of the document, or a specific part of it?

Is it acceptable to have the user open Word and export some (or all) of the document, or must activity that be hidden from the user?

Have you looked into using VBA (Microsoft Visual Basic for Applications) to export the document or copy it to the clipboard?

So many ways of attacking your problem, so we need more info to help you.

Harrison
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

Dear Harrison;
Thank you.

Please be informed that I want to read the file directly with/without using MS Word.

It may be ALL of the document, or a specific part of it.

It is acceptable to have the user open Word and export some (or all) of the document.

Have you looked into using VBA (Microsoft Visual Basic for Applications) to export the document or copy it to the clipboard? No, but could you help me in this direction with a specific examples.

Your fast action will be highly appreciated.

AHMED
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Copy from Word to Windows clipboard, retrieve from clipboard in your application with

Code: Select all

tryGetString/0-> tryGetString : () -> string String determ.
It is acceptable to have the user open Word and export some (or all) of the document.
That's the fastest way to get started since you don't seem to have strict requirements about not opening the document in Word.
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

Dear Sir;
I would like to draw you attention that I have a form and I want to access an external file in somewhere on the hard disk through the form. Then open the file and read its contents and make a copy of all or a specific part from it.

How could you help me by more details about tryGetString predicate usage.

Thank you.

Best regards;

AHMED NADY
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

Dear Sir;
Could you help me to solve this problem?
regards;
AHMED NADY
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

If your requirement is just about the reading a data from external file, you could find the below code,

Code: Select all

predicates     onPushButtonClick : button::clickResponder. clauses     onPushButtonClick(_Source) = button::defaultAction:-         MyStream = inputStream_file::openFile8(@"D:\TestMe.txt"),  %External file         MYVal = varM{string}::new(""),         %Loop through all the line and fetch a data from the file         std::repeat(),         if not(MyStream:endOfStream()) then             LieVal = MyStream:readLine(),             MYVal:value := string::concat(MYVal:value, LieVal, "\n"),  %Keep a copy @ Temp variable             fail %fail to loop through         end if,         MyStream:close(),  %Close the input stream handle         edit_ctl:setText(MYVal:value),  %display the message to edit control.         !.     onPushButtonClick(_Source) = button::defaultAction.
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi,

:idea: Something like :

Code: Select all

predicates     onTest1 : window::menuItemListener. clauses     onTest1(_Source, _MenuTag):-         Path = "C:\\",         Type = "*.doc",         List_doc_files = [F||F = directory::getFilesInDirectory_nd(Path,Type)],         foreach Cpt = std::fromTo(0,list::length(List_doc_files)-1) do             Fic = fileName::setPath(list::nth(Cpt,List_doc_files),Path),             read_doc_file(Fic)         end foreach.   predicates read_doc_file:(string DocFile) procedure(i). clauses read_doc_file(Fic):-                 MyStream = inputStream_file::openFile8(Fic),  %External file         MYVal = varM{string}::new(""),         %Loop through all the line and fetch a data from the file         std::repeat(),         if not(MyStream:endOfStream()) then             LieVal = MyStream:readLine(),             MYVal:value := string::concat(MYVal:value, LieVal, "\n"),  %Keep a copy @ Temp variable             fail %fail to loop through         end if,         MyStream:close(),  %Close the input stream handle         !. read_doc_file(_).
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

Dear Sir;
Thank you.
Where I can put these predicates?
How can I use it?
regards;
AHMED
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

...when user click on a button, like it :

Code: Select all

predicates     onPushButtonClick : button::clickResponder. clauses     onPushButtonClick(_Source) = button::defaultAction:-         Path = "C:\\",         Type = "*.doc",         List_doc_files = [F||F = directory::getFilesInDirectory_nd(Path,Type)],         foreach Cpt = std::fromTo(0,list::length(List_doc_files)-1) do             Fic = fileName::setPath(list::nth(Cpt,List_doc_files),Path),             read_doc_file(Fic)         end foreach.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Most suggestions above will not work.

The doc format used by Microsoft Word is an undocumented proprietary format.

The newer docx format follows a public standard. That does however not help much. A docx file is actually a zipped directory. If you change the extension to zip you can unpack it and see that its contents is rather difficult to find heads and tails in.

I suggest that you (either give up :oops: or) look for ways where Microsoft Word or some third party tool makes the conversion. Letting Microsoft Word put the relevant text on the clipboard is one possibility.
Regards Thomas Linder Puls
PDC
Post Reply