Using Alpha5 v1.02 under Windows 3.11, I have a number of RTF files I want to import into a memo field (defined via Field Rules as a Rich Text memo). For example, 01.rtf should go into the memo field of record 1, then 02.rtf should go into record 2, etc.
I can easily do this manually: bring up (say) record 1, switch to Change mode, click in my Ruch Text memo filed (named GoldText) then choose the menu command "Edit -> Import RTF File..." and pick the relevant .rtf file (ie 01.rtf). But I want this to happen automatically, so that documents 01.rtf to 10.rtf are imported into records 1 to 10 (one per record, of course), in sequence.
Here's what I've tried so far: none of these methods does what I want, though.
Method 1) Use the "memo_read_from_file" function - I got the idea from Melvin S Davidson's scripts in the Code Archive part of the Phorum:
filename = ui_get_file("Choose the Rich Text file", "RTF files (*.RTF)") 'we pick a file, say 02.rtf
dbh = db_current()
change_begin(dbh) 'before this we would first ensure we were at the right record - say record 2
memo_read_from_file(field_handle_get("TestRich->GoldText"), filename)
change_end(dbh, .T.)
card_resynch()
No good. Gives "Error in Rich Text message" in the field as seen on the form.
Method 2) First we'd use DDE commands from Alpha5 to Word (version 6.0c) to make Word open - say - 03.rtf if the current Alpha5 record was number 3. Then, again with DDE, we'd select all the text in the open Word rtf document & copy it to the clipboard, as this code snippet successfully shows:
DIM dsh as N
'sys_shell("c:msofficewinword.exe") 'use this line if Word not already running
dsh = dde_initiate("winword", "system")
dde_execute(dsh, "[EditSelectAll]")
dde_execute(dsh, "[EditCopy]")
dde_terminate(dsh)
Then paste the clipboard text to the Rich Text memo field (whose object name on the Alpha5 form is "ObjGoldText" ), by switching to change mode, clicking in the Rich Text memo field, and pressing Control-V. If you do this manually, it works fine. But if you try and automate (as in code snippet below), it doesn't work.
DIM dbh as N
DIM dsh as N
dbh = db_current()
obj_goto("ObjGoldText")
change_begin(dbh)
menu_run("Edit/Paste") } use only one of these lines,
sys_send_keys("^V") } but neither do the trick....
change_end(dbh, .T.)
Method 3) Here, again I've already got the desired rtf document open in Word, and it's a short (much less than 256 characters) one. My Rich Text Memo field is named "GoldText" and it's part of the database named "TestRich."
DIM dbh as N
DIM dsh as N
DIM gotdoc as C
dbh = db_current()
dsh = dde_initiate("winword", "01.rtf") 'where 01.rtf is the name of the RTF file currently open in Word
gotdoc = dde_request(dsh, "doc") 'Note that doc is the name of M$ pre-defined bookmark (viz entire text of the open document)
dde_terminate(dsh)
ui_msg_box("Look what I found!",gotdoc) 'This displays (up to the first 256 characters of) the document
'The following lines give "Error in rich text" message (and no other visible text) in the GoldText field, even though a hex editor shows the GoldText text has been "imported" into the TestRich.FPT file:
'change_begin(dbh)
' TestRich->GoldText = gotdoc 'where GoldText is name of a rich text memo field
'change_end(dbh, .T.)
'card_resynch()
'The following lines also give "Error in rich text" message (and no other visible text) in the GoldText field:
'change_begin(dbh)
' field_value_put(field_handle_get("TestRich->GoldText"), gotdoc)
'change_end(dbh, .T.)
'card_resynch()
'These lines, using an *ordinary* memo field, *do* work (though - of course - none of the Rich Text formatting is available).
change_begin(dbh)
TestRich->NormText = gotdoc 'where NormText is name of an ordinary memo field
change_end(dbh, .T.)
card_resynch()
Method 4) Use the "file_read" function... Haven't yet tried this. Would have to read (and write) 256 characters at a time, which would be fine for a text file but (I imagine) complicated with a Rich Text file due to its embedded "formatting instructions."
Method 5) Use calls (from Alpha5) to the Windows API to paste the text into the GoldText field (after using first half of Method 1 to get the .rtf file onto the clipboard). This is beyond me!
Any thoughts on whether this problem is solvable would be very welcome!
With thanks for any and all help.
Chris Ohlsen (London UK)
I can easily do this manually: bring up (say) record 1, switch to Change mode, click in my Ruch Text memo filed (named GoldText) then choose the menu command "Edit -> Import RTF File..." and pick the relevant .rtf file (ie 01.rtf). But I want this to happen automatically, so that documents 01.rtf to 10.rtf are imported into records 1 to 10 (one per record, of course), in sequence.
Here's what I've tried so far: none of these methods does what I want, though.
Method 1) Use the "memo_read_from_file" function - I got the idea from Melvin S Davidson's scripts in the Code Archive part of the Phorum:
filename = ui_get_file("Choose the Rich Text file", "RTF files (*.RTF)") 'we pick a file, say 02.rtf
dbh = db_current()
change_begin(dbh) 'before this we would first ensure we were at the right record - say record 2
memo_read_from_file(field_handle_get("TestRich->GoldText"), filename)
change_end(dbh, .T.)
card_resynch()
No good. Gives "Error in Rich Text message" in the field as seen on the form.
Method 2) First we'd use DDE commands from Alpha5 to Word (version 6.0c) to make Word open - say - 03.rtf if the current Alpha5 record was number 3. Then, again with DDE, we'd select all the text in the open Word rtf document & copy it to the clipboard, as this code snippet successfully shows:
DIM dsh as N
'sys_shell("c:msofficewinword.exe") 'use this line if Word not already running
dsh = dde_initiate("winword", "system")
dde_execute(dsh, "[EditSelectAll]")
dde_execute(dsh, "[EditCopy]")
dde_terminate(dsh)
Then paste the clipboard text to the Rich Text memo field (whose object name on the Alpha5 form is "ObjGoldText" ), by switching to change mode, clicking in the Rich Text memo field, and pressing Control-V. If you do this manually, it works fine. But if you try and automate (as in code snippet below), it doesn't work.
DIM dbh as N
DIM dsh as N
dbh = db_current()
obj_goto("ObjGoldText")
change_begin(dbh)
menu_run("Edit/Paste") } use only one of these lines,
sys_send_keys("^V") } but neither do the trick....
change_end(dbh, .T.)
Method 3) Here, again I've already got the desired rtf document open in Word, and it's a short (much less than 256 characters) one. My Rich Text Memo field is named "GoldText" and it's part of the database named "TestRich."
DIM dbh as N
DIM dsh as N
DIM gotdoc as C
dbh = db_current()
dsh = dde_initiate("winword", "01.rtf") 'where 01.rtf is the name of the RTF file currently open in Word
gotdoc = dde_request(dsh, "doc") 'Note that doc is the name of M$ pre-defined bookmark (viz entire text of the open document)
dde_terminate(dsh)
ui_msg_box("Look what I found!",gotdoc) 'This displays (up to the first 256 characters of) the document
'The following lines give "Error in rich text" message (and no other visible text) in the GoldText field, even though a hex editor shows the GoldText text has been "imported" into the TestRich.FPT file:
'change_begin(dbh)
' TestRich->GoldText = gotdoc 'where GoldText is name of a rich text memo field
'change_end(dbh, .T.)
'card_resynch()
'The following lines also give "Error in rich text" message (and no other visible text) in the GoldText field:
'change_begin(dbh)
' field_value_put(field_handle_get("TestRich->GoldText"), gotdoc)
'change_end(dbh, .T.)
'card_resynch()
'These lines, using an *ordinary* memo field, *do* work (though - of course - none of the Rich Text formatting is available).
change_begin(dbh)
TestRich->NormText = gotdoc 'where NormText is name of an ordinary memo field
change_end(dbh, .T.)
card_resynch()
Method 4) Use the "file_read" function... Haven't yet tried this. Would have to read (and write) 256 characters at a time, which would be fine for a text file but (I imagine) complicated with a Rich Text file due to its embedded "formatting instructions."
Method 5) Use calls (from Alpha5) to the Windows API to paste the text into the GoldText field (after using first half of Method 1 to get the .rtf file onto the clipboard). This is beyond me!
Any thoughts on whether this problem is solvable would be very welcome!
With thanks for any and all help.
Chris Ohlsen (London UK)