Is this Netopen function from 16 bit ok for FWH32 ?

Is this Netopen function from 16 bit ok for FWH32 ?

Postby Marc Venken » Fri Sep 22, 2017 12:58 pm

Hello,

In my project of converting from 16 bit to FWH, i need to change all my Ntx and partial COMIX files to CDX FWH.

I have the folowing code for opening files in FW16 :

Is this code still a good code, (change the COMIX to CDX...) or should I find a better one that uses more of FWH Power.

Maybe someone can share his code to open in network situation ?

At this point, I want to convert strait from 16 to 32. Later I could change to Objects, or other options.

Thanks.


Code: Select all  Expand view
FUNCTION NETOPEN( cFile, lMode, cAlias, nSeconds, lNewArea,cDriver, lReadOnly )
local nWaitTime, lContinue := .t., lSuccess  := .f., TSEL      := 0

DEFAULT lMode     :=  .T.                     // shared mode
DEFAULT nSeconds  :=  3
DEFAULT cAlias    := cFile
DEFAULT lNewArea  :=  .t.
DEFAULT cDriver   := "COMIX"
//DEFAULT cDriver   := "DBFNTX"
DEFAULT lReadOnly :=  .f.
nWaitTime := nSeconds

// bestand het bestand
IF ! FILE( cFile + ".DBF" )
   Exit("Bestand " + CFILE + ".DBF is afwezig")
ENDIF
// verify driver is valid
if ascan( RddList(), cDriver ) == 0
   MSGSTOP("Driver " + Cdriver + "  afwezig")
   Exit()
endif
//
// Indien reeds geopend, alles ok, select waar
//
IF SELECT(cAlias) # 0
   MsgInfo("File was reeds geopend")
   TSEL := SELECT(cAlias)
   SELECT(TSEL)
   lContinue := .t.
   lNewArea  := .f.
ENDIF
// while continuing to attempt open
Do while lContinue // while .not. timed-out
   while nSeconds > 0 .and. lContinue
     //dbUseArea( lNewArea, cDriver, cFile, cAlias, ( .not. lMode ), lReadOnly )
     dbUseArea( lNewArea, cDriver, cFile, cAlias, lMode, lReadOnly )
     // check for success/failure
     IF neterr()
       nSeconds--
       lSuccess  := .F.
      else
       // open successful
       nSeconds  := 0
       lSuccess  := .t.
       lContinue := .f.
     ENDIF
  ENDDO
  IF ! lSuccess
      nSeconds  := nWaitTime
      MSGSTOP("Bestand " + CFILE+" Alias : "+cAlias + " is geopend door een andere gebruiker" + CRLF + CRLF + "Gelieve even te wachten")
      lSuccess   := .F.
      lContinue  := .T.
      lNewArea   := .T.
  ENDIF
ENDDO

return lSuccess
 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Is this Netopen function from 16 bit ok for FWH32 ?

Postby Rick Lipkin » Fri Sep 22, 2017 1:49 pm

Marc

This User Defined Function has served me well .. the rdd is set for DbfCdx

Rick Lipkin

Code: Select all  Expand view

/* LOGICAL NETUSE( CDATABASE, LOPENMODE, NSECONDS )

  CHARACTER CDATABASE      - NAME OF DATABASE
  LOGICAL LOPENMODE        - OPEN MODE .T. exclusive  .F. shared
  NUMERIC NSECONDS         - NUMBER OF SECONDS TO WAIT  0 forever

  RETURN  .T. if successful,  .F. if not

  SAMPLE CALL  IF NETUSE( "CALLS.DBF", .F., 5 )  // you may need to use the full path and location to open the .dbf
*/

//------------------------------
Func NETUSE( CDATABASE, LOPENMODE, NSECONDS )

LOCAL FOREVER, RESTART, WAIT_TIME, YESNO

RESTART := .T.
FOREVER := ( NSECONDS = 0 )
YESNO   := {"Yes" , "No"}

DO WHILE RESTART

   WAIT_TIME := NSECONDS

   DO WHILE ( FOREVER .OR. WAIT_TIME > 0 )

      IF LOPENMODE
         USE ( CDATABASE ) via "DBFCDX" EXCLUSIVE
      ELSE
         USE ( CDATABASE ) via "DBFCDX" SHARED
      ENDIF

      IF .NOT. NETERR()
         RETURN(.T.)
      ENDIF
      INKEY(1)
      WAIT_TIME--

   ENDDO

   * lock failed, ask to continue

   IF MsgYesNo( "Cannot lock " + CDATABASE + ", retry ?" )
   ELSE
      EXIT
   ENDIF

ENDDO

RETURN(.F.)

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Is this Netopen function from 16 bit ok for FWH32 ?

Postby TimStone » Fri Sep 22, 2017 4:29 pm

I use CDX, and tData ( Database objects ). I haven't worried about network locking in YEARS ... it should all be automatic. It's also a lot simpler. ALL of my installs are networked.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Is this Netopen function from 16 bit ok for FWH32 ?

Postby Marc Venken » Fri Sep 22, 2017 6:48 pm

TimStone wrote:I use CDX, and tData ( Database objects ). I haven't worried about network locking in YEARS ... it should all be automatic. It's also a lot simpler. ALL of my installs are networked.


I totaly agree.. I have more than once talked with James, and got a lot of info, and I'm convinced about Objects. I even use them i smaller apps, but for my bigger program, I first need to get it going in FWH.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Is this Netopen function from 16 bit ok for FWH32 ?

Postby Rick Lipkin » Sun Sep 24, 2017 2:04 pm

Marc

Along the subject Tim brings up ... you might want to consider moving to the Ado Class and Methods.

https://docs.microsoft.com/en-us/sql/ad ... object-ado

Benefits:

1) Ado oRs code is the same whether you use Ms Sql Server, Ms Access or Oracle .. MySql and MariaDB are similar.
2) Ado leverages Opportunistic Locking where as .DbfCdx has documented Opportunistic Locking performance issues in a Mult-User network environment
3) Ado allows Ms Access and Ms Sql server to share ( virtually ) the same code .. just change the connection string.
4) Modern SQL code is very desirable with many CIO's

It sounds like you are on the verge of a major re-write anyway ... please have a look at the sample AdoRick.Prg .. a good example on how to start using Ado and MS Access .. also on how to implement increment filtering ..

Rick Lipkin

ps .. I thought you were using Ado already in some of your other projects ?
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests