Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
String Too Long to Fit
Message
De
13/05/2000 10:45:55
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
13/05/2000 09:22:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00369164
Message ID:
00369337
Vues:
20
>Hi Cetin,
>
>I'm running VFP 6.0 on an NT 4.0 workstation with 128mg.
>
>It appears that I have happened upon an anomaly that others may have encountered also.
>
>In a SQL Select statement that has the parameter 'Into Table TableName', if TableName is not in the path I get a "String too long to fit" message on the entire Select statement of course.
>
>In the app I'm currently have a problem with I setup the following:
>
>lcTempDir = "C:\CVS\"
>
>other code...later after creating a Word Object:
>
>lcDocument=lcTempDir+"BetExp01.doc"
>.Documents.open(lcDocument)
>
>If BetExp01.doc is not in the path I get a "String too long to fit" message at the .Documents.open(lcDocument) statement.


Paige,
I think the error here is related with SQL statement used in mailmerge (I guess this is part of an mailmerge). In ODBC connect string there are 2 SQLstring parameters. Each could hold up to 255 chars. Probably you use only the first one and if path gets long 255 is exceeded. When it's exceeded second SQLstring should be used. You could work around it :

lcSQL1 = iif(len(lcSQL) > 255, left(lcSQL,255), lcSQL)
lcSQL2 = iif(len(lcSQL) > 255, substr(lcSQL,256), "")

Better yet I would suggest not to use mailmerge with ODBC at all :) Here is a sample of whatI do :
Wait window nowait "Creating Word Document.Please wait..."
* Word constants header file
#include "wdconst.h"
#Define NL chr(13)
#Define TABULATE chr(9)

* VFP3-5
*lnFields=_CopyDataToClipBoard(home()+"samples\data\employee","first_name,last_name,title,hire_date,notes")
* VFP6
* Copy VFP data to clipboard
Select * from (_samples+"\data\employee") where Title like  "%Manager%" into table Tempreport
lnFields=_CopyDataToClipBoard("Tempreport","first_name,last_name,title,hire_date,notes")

*** set the LOCALEID to English
nlLocaleId=sys(3004)  && Save local id
=sys(3006,1033)       && We will be sending instructions in English
*** set the LOCALEID to English
Public oWordDocument
oWordDocument=createobject("word.application")	&& Create word object
With oWordDocument
  .documents.add	&& New file
  *  .Application.DefaultTableSeparator = "~"
  With .ActiveDocument
    .PageSetup.Orientation = wdOrientLandscape  && Set to landscape
    .Range.Paste      && Paste VFP data
    .Range.ConvertToTable(wdSeparateByTabs,,lnFields,,wdTableFormatContemporary,,,,,,,,,.f.) && Convert to table
    .Range.Find.Execute("~",,,,,,,,,"^p",wdReplaceAll) && Restore memo para marks
  Endwith
  =_SampleMerge(.f.) && Do mailmerge
  .ActiveDocument.MailMerge.Destination = wdSendToNewDocument
  .ActiveDocument.MailMerge.Execute
  .ActiveDocument.Range.Find.Execute("^b",,,,,,,,,"^p^p[End of Merge]^p",wdReplaceAll) && Replace section breaks with para marks
  .visible = .t.  && Show word app
  .Activate  && Make it the active foreground app
Endwith
Wait clear
**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))


*******************************************************************
* Insert a table in Word at specified bookmark - NonODBC safe way
*******************************************************************
Function _CopyDataToClipBoard
  Lparameters tcTableName, tcFieldList

  lcOldAlias = Alias()  && Save alias
  Select &tcFieldList ;
    from (tcTableName) ;
    nofilter into cursor crsTemp  && Select recs into a cursor
  If reccount("crsTemp")=0
    Use in "crsTemp"
    Return
  Endif
  Select crsTemp
  lnFields = fcount()
  lcTempFileName = "X"+sys(2015)+".tmp"
  handle = fcreate(lcTempFileName)  && Create a temp file
&& Write header line
  For ix = 1 to lnFields
    =fwrite(handle, field(ix))
    If ix < lnFields
      =fwrite(handle, TABULATE)
    Endif
  Endfor
  =fwrite(handle, NL)
  Scan    && Start scan..endscan
    For ix = 1 to lnFields
      =fwrite(handle, TypeConvert(ix) ) && Write converting all to char type
      If ix < lnFields
        =fwrite(handle, TABULATE)
      Endif
    Endfor
    =fwrite(handle, NL)
  Endscan
  lnSize=fseek(handle,0,2)
  =fseek(handle,0,0)
  _Cliptext = fread(handle, lnSize)  && Read file to clipboard
  =fclose(handle)
  Erase (lcTempFileName)
  * Prepare text copied to clipboard in VFP which is much faster than Word OLE

  Use in "crsTemp"
  If !empty(lcOldAlias)
    Select (lcOldAlias)
  Endif
  Return lnFields

Function TypeConvert && Convert VFP data types to char
  Lparameters tnField
  lcType = type(field(ix))
  luValue = eval(field(ix))
  Do case
    Case lcType = "D"
      lcValue = dtoc(luValue)
    Case lcType = "T"
      lcValue = ttoc(luValue)
    Case lcType = "N"
      lcValue = padl(luValue,20," ")
    Case lcType = "L"
      lcValue = iif(luValue,"Yes","No")
    Case lcType $ "MC" && Replace paragraph marks with "~"
      lcValue = chrtran(strtran(luValue, chr(13)+chr(10), "~"),chr(9),space(4))
    Otherwise
      lcValue = ""
  Endcase
  Return alltrim(lcValue)

Function _SampleMerge
  Lparameters tlToPrinter
  With oWordDocument
    lcTempDataDoc = sys(5)+curdir()+"T"+sys(2015)+".doc"
    With .ActiveDocument
      .SaveAs(lcTempDataDoc)  && Save as a word doc for mailmerge - datasource
      .Close(wdSaveChanges)   && Close saving
    Endwith

    .documents.add  && New file or open a template
    With .ActiveDocument.MailMerge
      .OpenDataSource(lcTempDataDoc) && Set saved file as data source for mailmerge (Directly a table could be set via ODBC)
      .EditMainDocument	&& Activate the main document
    Endwith
    .Application.Selection.TypeText("Dear,"+chr(13))
    .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "LAST_NAME")
    .Application.Selection.TypeText(", ")
    .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "FIRST_NAME")
    .Application.Selection.TypeText(chr(13)+"Here is your notes data :"+chr(13)+chr(13))
    .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "NOTES")
    .Application.Selection.TypeText(chr(13)+chr(13)+"As to our records you were hired on ")
    .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "HIRE_DATE")
    .Application.Selection.TypeText(" with title [")
    .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "TITLE")
    .Application.Selection.TypeText("]"+chr(13)+"Thanks"+chr(13)+"Yours Sincerely."+chr(13)+"Blah blah...")
  Endwith
Cetin


>
>I've resolved these problems but now get the message "String too long to fit" at the .application.run("Replace") command in the routine below used to replace text in a Word template.
>
>NewText = MDY(DATE()) && Thanks to Bret
>DO WordRepl WITH "<>", NewText
>
>WordRepl Routine follows:
>
>Lparameters OldText, NewText
>*
>* Replace All OldText with NewText
>*
>
>WITH oWORDDOC
>
> .Selection.Find.ClearFormatting
> .Selection.Find.Replacement.ClearFormatting
>
> .Selection.Find.Text = OldText
> .Selection.Find.Replacement.Text = NewText
> .Selection.Find.Wrap = 1
> .Selection.Find.Format = .f.
> .Selection.Find.MatchCase = .f.
> .Selection.Find.MatchWholeWord = .f.
> * Word.Selection.Find.MatchWildcards = False
> * Word.Selection.Find.MatchSoundsLike = False
> * Word.Selection.Find.MatchAllWordForms = False
>
> .application.run("replace")
>
>ENDWITH
>
>I don't know how much memory the RUN command requires. I could be running out of memory on the users workstation although she has 128mg on her Win98 workstation but is running from a NT 4.0 server.
>
>Sys(1016) returns 726624 on my workstation just prior to executing the Run command. I havn't checked her machine.
>
>There may be a more efficient method to accomplish the Word Replace. I use this to "REPLACE" name, address, and other data in the template also. If you know a better way I would appreciate you sharing it with me. TIA.
>
>Regards,
>
>Paige
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform