Prev: Spinners
Next: Exchange
From: John Martens on
Woerdie,

Your code should (at least) look something like this:

LOCAL oOutput as FacturenOutput
oOutput := FacturenOutput{} // Open the DBF
oOutput:Append() // Append a record
oOutput:Fieldput(n,SELF:oDCBrowseGrid:oDBServer:FIELDGET(n)) // Fill a field
oOutput:Close() // Close the DBF

FacturenOutput should be something like this

CLASS FacturenOutput INHERIT Facturen // Make sure you can use all of
your Facturen code
METHOD Init(cDBF, lShare, lRO, xRdd) CLASS FacturenOutput
LOCAL oFileToClone AS Facturen{}
oFileToClone := Facturen{}
aDBStructure := {}
aDBStructure := oFileToClone:DBStruct
DBCREATE(oSystem:WorkDir + "\FACTUREN.DBF", aDBStructure, "DBFCDX",
TRUE, "oOutput")
oFileToClone:Close()

SUPER:Init(oSystem:WorkDir + "\FACTUREN.DBF", lShare, lRO, xRdd) //
Open the copied file so the oOutputFacturen object will be open

RETURN SELF

Cheers,
John


Op 1-4-2010 18:21, Woerdie schreef:
> On 1 apr, 00:04, Takumo<advokat.b...(a)gmail.com> wrote:
>> Hi!
>> More over - check if your database is shared and opened somewhere
>> else.
>> As help says: "Shared mode: For a shared database, this function
>> requires a record lock. Refer to the "Concurrency Control" chapter in
>> the Programmer's Guide for more information on locking".
>>
>> If this mixed approach works in other parts of your code, check return
>> value of DBAppend() and NetErr() state . There may be an error in
>> dbappend because it should lock an appended record automatically. If
>> the lock fails, the prog execution continues and you may get an error
>> message somewhere in the rest part of your code.
>>
>> HTH.
>
>
> When I Try
> oOutput:Append()
> .....
> oOutput:Fieldput(n,SELF:oDCBrowseGrid:oDBServer:FIELDGET(n))
>
> VO says: Unknown valriable oOUTPUT
>
>
> Init oOutput =
>
> oFileToClone := Facturen{}
> aDBStructure := {}
> aDBStructure := oFileToClone:DBStruct
>
> DBCREATE(oSystem:WorkDir + "\FACTUREN.DBF", aDBStructure, "DBFCDX",
> TRUE, "oOutput")
> oFileToClone:Close()
From: Woerdie on
On 1 apr, 19:12, John Martens <adsl672...(a)tiscali.nl> wrote:
> Woerdie,
>
> Your code should (at least) look something like this:
>
> LOCAL oOutput as FacturenOutput
> oOutput := FacturenOutput{}  // Open the DBF
> oOutput:Append() // Append a record
> oOutput:Fieldput(n,SELF:oDCBrowseGrid:oDBServer:FIELDGET(n)) // Fill a field
> oOutput:Close() // Close the DBF
>
> FacturenOutput should be something like this
>
> CLASS FacturenOutput INHERIT Facturen  // Make sure you can use all of
> your Facturen code
> METHOD Init(cDBF, lShare, lRO, xRdd) CLASS FacturenOutput
>    LOCAL oFileToClone AS Facturen{}
>    oFileToClone := Facturen{}
>    aDBStructure  := {}
>    aDBStructure  := oFileToClone:DBStruct
>    DBCREATE(oSystem:WorkDir + "\FACTUREN.DBF", aDBStructure, "DBFCDX",
> TRUE, "oOutput")
>    oFileToClone:Close()
>
>    SUPER:Init(oSystem:WorkDir + "\FACTUREN.DBF", lShare, lRO, xRdd) //
> Open the copied file so the oOutputFacturen object will be open
>
> RETURN SELF
>
> Cheers,
> John
>
> Op 1-4-2010 18:21, Woerdie schreef:
>
> > On 1 apr, 00:04, Takumo<advokat.b...(a)gmail.com>  wrote:
> >> Hi!
> >> More over - check if your database is shared and opened somewhere
> >> else.
> >> As help says: "Shared mode: For a shared database, this function
> >> requires a record lock.  Refer to the "Concurrency Control" chapter in
> >> the Programmer's Guide for more information on locking".
>
> >> If this mixed approach works in other parts of your code, check return
> >> value of DBAppend() and NetErr() state . There may be an error in
> >> dbappend because it should lock an appended record automatically. If
> >> the lock fails, the prog execution continues and you may get an error
> >> message somewhere in the rest part of your code.
>
> >> HTH.
>
> > When I Try
> > oOutput:Append()
> > .....
> > oOutput:Fieldput(n,SELF:oDCBrowseGrid:oDBServer:FIELDGET(n))
>
> > VO says: Unknown valriable oOUTPUT
>
> > Init oOutput =
>
> >    oFileToClone := Facturen{}
> >    aDBStructure  := {}
> >    aDBStructure  := oFileToClone:DBStruct
>
> >    DBCREATE(oSystem:WorkDir + "\FACTUREN.DBF", aDBStructure, "DBFCDX",
> > TRUE, "oOutput")
> >    oFileToClone:Close()
>
>

Thanks John, I got now this code:
METHOD GenereerArtDbf2(cOutput, cSortGang, cFile, cBeginBijEtiket)
CLASS FacturenBrowse
LOCAL nCurrentRecno as word
LOCAL oWin as PrintProgress
LOCAL n, y as word

lOCAL oOutput as FacturenOutput

oOutput := FacturenOutput{} // Open the DBF

Select oOutput

// GA NU HET BESTAND VULLEN...

nCurrentRecno := self:oDCBrowseGrid:oDBServer:Recno

self:oDCBrowseGrid:oDBServer:SuspendNotification()
self:oDCBrowseGrid:GoTop()

oWin := PrintProgress{oSystem:Shell,
Range{0,oDCBrowseGrid:oDBServer:OrderKeyCount()},int(oDCBrowseGrid:oDBServer:OrderKeyCount()/
10)}
IF oDCBrowseGrid:oDBServer:OrderKeyCount() > 20
oWin:Show()
ENDIF
// Ga de Artikelen doorlopen...
DO WHILE !self:oDCBrowseGrid:oDBServer:Eof

IF self:oDCBrowseGrid:oDBServer:Betaald == FALSE
IF oOutput:Append()
y := self:oDCBrowseGrid:oDBServer:FCount
FOR n := 1 to y
oOutput:FIELDPUT(n,self:oDCBrowseGrid:oDBServer:FIELDGET(n)) //
Fill a field
NEXT n
ENDIF
ENDIF
self:oDCBrowseGrid:oDBServer:Skip(1)

if oWin:Update()
exit
Endif

ENDDO

oWin:EndDialog()

self:oDCBrowseGrid:GoTo(nCurrentRecno)
self:oDCBrowseGrid:oDBServer:ResetNotification()

oOutput->(DBCREATEORDER("FACTUURNR",oSystem:WorkDir +
"\FACTUREN.CDX","FACTUURNR"))
oOutput:Close() // Close the DBF LOCAL n, y AS WORD

RETURN self
CLASS FacturenOutput INHERIT Facturen // Make sure you can use all of
your Facturen code
METHOD Init(cDBF, lShare, lRO, xRdd) CLASS FacturenOutput
LOCAL oFileToClone as Facturen
LOCAL aDBStructure as ARRAY

oFileToClone := FACTUREN{}
aDBStructure := {}
aDBStructure := oFileToClone:DBStruct
DBCREATE(oSystem:WorkDir + "\FACTUREN.DBF", aDBStructure,
"DBFCDX",true, "oOutput")
oFileToClone:Close()

SUPER:Init(oSystem:WorkDir + "\FACTUREN.DBF", lShare, lRO, xRdd) //
Open the copied file so the oOutputFacturen object will be open

RETURN self
--------------------------------------
Now this code gives me an error on line:
oOutput := FacturenOutput{} // Open the DBF

Error message:
--------------
Error Code: 21 [ OPEN ERROR ]
Subsystem: DBFCDX
Error Subcode: 1101 (Open database)
Function: INIT
Filename: .....
CallStack:
DIJOSERVER:INIT (Line:13)
FACTUREN:INIT (Line:65)
FACTURENOUTPUT:INIT (Line:11)
FACTURENBROWSE:GENEREERARTDBF2 (Line:8)
FACTURENBROWSE:PRINTFACTURENOPENSTAAND (Line:13)

Error Object created:
--------------------
SubSystem :DBFCDX
SubCode :1101
GenCode :Open error
OsCode :3
ArgType :NIL
FuncPtr :0x00000000
ArgNum :0
FuncSym :INIT
Severity :2
CanDefault :.F.
CanRetry :.T.
CanSubstitute :.F.
Operation :
Description :
FileName :D:\.....\TEMP\FACTUREN.DBF
Tries :1
FileHandle :0
SubCodeText :Open database
Arg :
ArgTypeReq :NIL
MaxSize :0
SubstituteType :NIL
CallFuncSym :
From: Geoff Schaller on
Woerdie.

You are using aliased expressions again. DO NOT!


> oOutput := FacturenOutput{} // Open the DBF

This line of code is fine - at this point (and you can prove this
yourself) you should have the duplicated DBF and the oOutput server
instantiated.

> Select oOutput

LOSE THIS LINE OF CODE! This is clipper syntax and you are writing in OO
VO code. In fact I am not entirely sure what affect this may have <g>.

> DO WHILE !self:oDCBrowseGrid:oDBServer:Eof
> IF self:oDCBrowseGrid:oDBServer:Betaald == FALSE
> IF oOutput:Append()
> y := self:oDCBrowseGrid:oDBServer:FCount
> FOR n := 1 to y
> oOutput:FIELDPUT(n,self:oDCBrowseGrid:oDBServer:FIELDGET(n)) //
> Fill a field
....
> ENDDO

So this should be ok too now. If you stop the app at this point you
should see rows in oOutput but you are missing one final commit for the
last append - the others will be auto committed.

> oOutput->(DBCREATEORDER("FACTUURNR",oSystem:WorkDir +
> "\FACTUREN.CDX","FACTUURNR"))
> oOutput:Close() // Close the DBF LOCAL n, y AS WORD

Now you went and spoiled it again. USE THE DBSERVER EQUIVALENT. Do not
use clipper aliased expressions. It cannot work.

> CLASS FacturenOutput INHERIT Facturen // Make sure you can use all
of
> your Facturen code
> METHOD Init(cDBF, lShare, lRO, xRdd) CLASS FacturenOutput
> LOCAL oFileToClone as Facturen
> LOCAL aDBStructure as ARRAY
>
> oFileToClone := FACTUREN{}
> aDBStructure := {}
> aDBStructure := oFileToClone:DBStruct
> DBCREATE(oSystem:WorkDir + "\FACTUREN.DBF", aDBStructure,
> "DBFCDX",true, "oOutput")
> oFileToClone:Close()
>
> SUPER:Init(oSystem:WorkDir + "\FACTUREN.DBF", lShare, lRO, xRdd) //
> Open the copied file so the oOutputFacturen object will be open
>
> RETURN self

I really don't like any of this. You should be copying a table like
this:

IF oDB1:CopyStructure(oFSTarget)
oDB2 := DBServer{oFSTarget}
ELSE
... handle the error
ENDIF

This is straight out of the help file so you need to create the
oFileSpec - which is better than what you are doing anyway, Just avoid
clipper stuff altogether.

Geoff

> Now this code gives me an error on line:
> oOutput := FacturenOutput{} // Open the DBF

PS - this error suggests the table did not exist.

From: Stephen Quinn on
Woerdie

> IF self:oDCBrowseGrid:oDBServer:Betaald == FALSE
Don't evaluate LOGIC values, use
IF ! self:oDCBrowseGrid:oDBServer:Betaald
or
build the index TAG with a FOR clause { Betaald }
if you do this there's no need for the test<g>

> Select oOutput
There's never any need for Select statements when using objects

> Range{0,oDCBrowseGrid:oDBServer:OrderKeyCount()},int(oDCBrowseGrid:oDBServer:OrderKeyCount()/10)}
Read the help on using INT() and Integer() // VO isn't Clipper, things
changed

> oOutput->(DBCREATEORDER("FACTUURNR",oSystem:WorkDir +
"\FACTUREN.CDX","FACTUURNR"))

Your still using Clipper syntax - mixing things doesn't work very well, as
your finding out<g>

> Now this code gives me an error on line:
> oOutput := FacturenOutput{} // Open the DBF

Well it would as you DON'T have a FacturenOutput{} DBServer class in your
app.
If you have why are you using DBCREATE() to create it??
You should be using something like below
oOutput := DBServer{ 'TheFileNameOftheClonedDBF' } // Open the DBF
or
oOutput := FacturenOutput{ 'TheFileNameOftheClonedDBF' }
or
oOutput := FacturenOutput{ 'TheFileNameOftheClonedDBF' }
IF ! oOutput:Used
aStruct := oOutput:Struct
oDBF := DBFileSpec{ oOutput:FileSpec, aStruct } // Check syntax
oDBF:Create()
// Try again to open it
oOutput := FacturenOutput{ 'TheFileNameOftheClonedDBF' }
IF ! oOutput:Used
// Abort - as the file doesn't exist
BREAK
ENDIF
ENDIF

CYA
Steve


From: Woerdie on
On 2 apr, 02:11, "Stephen Quinn" <stevej...(a)bigpondSPAM.net.au> wrote:
> Woerdie
>
> > IF self:oDCBrowseGrid:oDBServer:Betaald == FALSE
>
> Don't evaluate LOGIC values, use
>     IF ! self:oDCBrowseGrid:oDBServer:Betaald
>     or
>     build the index TAG with a FOR clause { Betaald }
>         if you do this there's no need for the test<g>
>
> > Select oOutput
>
> There's never any need for Select statements when using objects
>
> > Range{0,oDCBrowseGrid:oDBServer:OrderKeyCount()},int(oDCBrowseGrid:oDBServer:OrderKeyCount()/10)}
>
> Read the help on using INT() and Integer()     // VO isn't Clipper, things
> changed
>
> > oOutput->(DBCREATEORDER("FACTUURNR",oSystem:WorkDir +
>
> "\FACTUREN.CDX","FACTUURNR"))
>
> Your still using Clipper syntax - mixing things doesn't work very well, as
> your finding out<g>
>
> > Now this code gives me an error on line:
> > oOutput := FacturenOutput{}  // Open the DBF
>
> Well it would as you DON'T have a FacturenOutput{} DBServer class in your
> app.
> If you have why are you using DBCREATE() to create it??
> You should be using something like below
>     oOutput := DBServer{ 'TheFileNameOftheClonedDBF' }  // Open the DBF
> or
>     oOutput := FacturenOutput{ 'TheFileNameOftheClonedDBF' }
> or
>     oOutput := FacturenOutput{ 'TheFileNameOftheClonedDBF' }
>     IF ! oOutput:Used
>         aStruct := oOutput:Struct
>         oDBF := DBFileSpec{ oOutput:FileSpec, aStruct }     // Check syntax
>         oDBF:Create()
>         // Try again to open it
>         oOutput := FacturenOutput{ 'TheFileNameOftheClonedDBF' }
>         IF ! oOutput:Used
>                 // Abort - as the file doesn't exist
>                 BREAK
>         ENDIF
>     ENDIF
>
> CYA
> Steve

Sorry Guys, When I now read all your comments I see 2 different
solutions and not knowing wich one to use...
I need a piece of code to create a temp table in a tempfolder:
oSystem:WorkDir + "\FACTUREN.DBF
and I need an object to use the created temp file and a piece of code
to
fill the temp table in a loop...
Now i am mixing up all of the suggestions and it is not working..

I now got:

METHOD GenereerArtDbf2(cOutput, cSortGang, cFile) CLASS
FacturenBrowse //cBeginBijEtiket
LOCAL nCurrentRecno as word
LOCAL oWin as PrintProgress
LOCAL n, y as word

//LOCAL oFileToClone as Facturen
LOCAL aDBStructure as ARRAY
lOCAL oOutput as FacturenOutput
LOCAL oFacturen as Facturen

oFacturen:=FACTUREN{}
aDBStructure:= oFacturen:DbStruct
oFacturen:Close()

DBCREATE(oSystem:Workdir +
"\FACTUREN.DBF",aDBStructure,"DBFCDX",true,"oOutput")

oOutput:=FacturenOutput{} // Open the DBF


// GA NU HET BESTAND VULLEN...
...existing loop (at least I understand this code is ok...



oOutput:Close() // Close the DBF

RETURN self
CLASS FacturenOutput INHERIT Facturen // Make sure you can use all of
your Facturen code
METHOD Init(cDBF, lShare, lRO, xRdd) CLASS FacturenOutput
// LOCAL oFileToClone as Facturen
// LOCAL aDBStructure as ARRAY

// oFileToClone := FACTUREN{}
// aDBStructure := {}
// aDBStructure := oFileToClone:DbStruct
// DBCREATE(oSystem:Workdir + "\FACTUREN.DBF", aDBStructure,
"DBFCDX",true, "oOutput")
// oFileToClone:Close()

SUPER:Init(oSystem:Workdir + "\FACTUREN.DBF", lShare, lRO, xRdd) //
Open the copied file so the oOutputFacturen object will be open

RETURN self

The temp file is created, but error once again on open error
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Spinners
Next: Exchange