• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

LibraryExport() for long script

I used LibraryExport() to export a Window object in PB5.
But the object is too large that it can only export partially.

How can I fix the problem if I want to use  script instead of the Export Painter
to export objects?
0
xo123
Asked:
xo123
  • 5
  • 5
1 Solution
 
namasi_navaretnamCommented:
Are you using PB 5.0 16 bit? Migrate to 32bit PB 5.0 then LibraryExport will work for string length greater than 64K.

16 bit string datatype can only hold 64K.
0
 
namasi_navaretnamCommented:
Btw, this is not PB limitation, but OS limitation.
0
 
xo123Author Commented:
I think I'm using 32bit.
This is the info from 'About'
    PowerBuilder Enterprise/32
           by Powersoft
       Version 5.0.04
  Copyright c 1991 - 1997 Sybase, Inc.
       and its subsidiaries.
.....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
namasi_navaretnamCommented:
Does the string gets truncated when you run the app thru development environment as well? What operating system you are using?

0
 
xo123Author Commented:
For any objects longer than 32 KB,
the libaryexport() can only export them to 32 KB long.
But if I used the Library painter's Export option, it can export successfully without loss.

Here's my coding:
   ....
   String  ls_objsyn
   ls_objsyn = LibraryExport( lib_path,  obj_name, DirWindow! )
   ....

0
 
xo123Author Commented:
I'm using Window 2000 Professional.
0
 
xo123Author Commented:
Oh.... I just discover one thing:
  FileWrite can write only 32,766 bytes at a time, which includes the string   terminator character. If the length of variable exceeds 32,765, FileWrite writes the first 32,765 characters and returns 32,765.

I'm using FileWrite() for writing the export script.

What can I do?
0
 
xo123Author Commented:
I'll try to partition the export script (ls_objsyn) and write each partition at a time.
0
 
namasi_navaretnamCommented:
OK. Using filewrite you can only write 32k at a time. Try PFCs of_FileWrite. I think of_filewrite can handle more than 32K.
0
 
namasi_navaretnamCommented:
Here is the PFCs FileWrite

//////////////////////////////////////////////////////////////////////////////
//
//      Function:  of_FileWrite
//
//      Access:  public
//
//      Arguments:
//      as_FileName                        The name of the file to write to.
//      as_Text                                    The text to be written to the file.
//      ab_Append                        True - append to the end of the file,
//                                                      False - overwrite the existing file.
//
//      Returns:            Integer
//                              1 if successful, -1 if an error occurrs.
//
//      Description:      Open, write to, and close a file.  Handles strings > 32,765 bytes.
//
//////////////////////////////////////////////////////////////////////////////
//
//      Revision History
//
//      Version
//      5.0   Initial version
//      6.0.01      Rewrite to handle strings > 60k making more than 2 passes (for 32 bit platforms)
//
//////////////////////////////////////////////////////////////////////////////
//
//      Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//      Any distribution of the PowerBuilder Foundation Classes (PFC)
//      source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

Integer            li_FileNo, li_writes, li_cnt
Long                  ll_StrLen, ll_currentpos
String            ls_Text
Writemode      lwm_Mode

If ab_Append Then
      lwm_Mode = Append!
Else
      lwm_Mode = Replace!
End if

li_FileNo = FileOpen(as_FileName, StreamMode!, Write!, LockReadWrite!, lwm_Mode)
If li_FileNo < 0 Then Return -1

ll_StrLen = Len(as_Text)

// If the string is longer than 32765 bytes then it will require multiple writes to write it
If ll_StrLen > 32765 Then
      If Mod(ll_StrLen, 32765) = 0 Then
            li_Writes = ll_StrLen / 32765
      Else
            li_Writes = (ll_StrLen / 32765) + 1
      End if
Else
      li_Writes = 1
End if

ll_CurrentPos = 1

For li_Cnt = 1 To li_Writes
      ls_Text = Mid(as_Text, ll_CurrentPos, 32765)
      ll_CurrentPos += 32765
      If FileWrite(li_FileNo, ls_Text) = -1 Then
            Return -1
      End if
Next

FileClose(li_FileNo)

Return 1
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now