May 25, 2022, 04:37:41 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


@RTSAVE using RichEdit

Started by billhsln, November 16, 2014, 11:38:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I am saving a RichEdit text in a Memo field of an Access Database.  The problem I have found using the following code:

length = CONTROLCMD(d1,d1_re,@RTGETTEXTLENGTH)
lpStr = new(char,length+500)
settype lpStr, string
RtlZeroMemory(lpStr,length+500)

nlen = CONTROLCMD(d1,d1_re,@RTSAVE,*lpStr,1)

MESSAGEBOX d1,"length="+STR$(length)+" nlen="+STR$(nlen),"Length"


Length=839, nlen=1294

Now this works with +1 when I use 0 in the RTSAVE, but when I use 1 it pulls a lot more data.  Is there some way to determine how much extra to add in when doing an RTF?  Or some rule of thumb as to how much extra to add in general.

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

I've looked all over the place and haven't been able to find a "magic" solution.

All I can come p with is two workarounds.
The first is, through trial and error, create a fixed string twice the size you think you will ever need.
The problem is that some day you might exceed that limit and loose part of a receipt.
I'd have to say this isn't my preferred method.

The other way is what I would do.
When I was ready to save the data:
  Save the contents of the RE to a tmp file
  Get the size of the tmp file
  Increase that size #by a few
  create your dynamic string using that size
  read the RE into the dynamic string and transfer it to the memo field
  delete the dynamic string
  delete the tmp file
  STORE the size number in a new column in your database
When I was ready to read the data:
  get the size from the database
  create your dynamic string using that size
  read the memo into the dynamic string and transfer it to the RE
  delete the dynamic string

With this method you don't have to worry about exceeding some fixed size.
And with the speed of PCs nowadays you want take a time hit.

That's all I can offer.  Hope it helps a little (or someone finds something simpler that I've missed)
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Is there a simple/quick way to get file size?

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

DECLARE IMPORT, GetFileSize(hFile:UINT, lpFileSizeHigh:UINT BYREF), UINT
UINT toread_high

DEF myfile as BFILE
IF OPENFILE(myfile, getstartpath+"Bread Pudding.txt", "R") = 0
uint toread = GetFileSize(myfile, toread_high)
print toread
   CLOSEFILE myfile
ENDIF
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Thanks, Larry.

That should solve the problem, at least it will let me continue working on the program.

Bill
When all else fails, get a bigger hammer.

fasecero

Just to play a bit with winapi after a while... I think this function can return the right size (requires Sapero include files)



$INCLUDE "windowssdk.inc"
$INCLUDE "Richedit.inc"

SUB GetRTFSize(WINDOW w, INT richID), INT
INT size = 0
EDITSTREAM eds

eds.dwCookie = &size
eds.dwError = 0
eds.pfnCallback = &rtfCallback
SENDMESSAGE(GETCONTROLHANDLE(w, richID), EM_STREAMOUT, SF_RTF, &eds)

RETURN size
ENDSUB

SUB rtfCallback(DWORD_PTR dwCookie, pointer pbBuff, LONG cb, pointer pcb), INT
*<INT> dwCookie = *<INT> dwCookie + cb
Sleep(10)

RETURN 0
ENDSUB



billhsln

Installed the code from fasecero and it worked perfectly, came up with the exact number of characters.

Thanks, fasecero.

Bill
When all else fails, get a bigger hammer.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library