home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / snip0693.zip / SCRLBAR2.PRG < prev    next >
Text File  |  1993-05-21  |  3KB  |  90 lines

  1.  
  2. Thanks for the code you sent to Michael Koh!  I've modified it to run under 
  3. 5.01 using the standard ntx driver and the NTXREC/NTXPOS functions.  I've also 
  4. noted the changes that have to be made when calling those functions to allow 
  5. for changes in the internals for 5.2.
  6.  
  7.  
  8.  /*
  9.     ShowScrollBar() - This function displays a simple vertical "scroll bar"
  10.                       for a TBrowse on the current table and index.  Call
  11.                       ShowScrollBar() with scroll bar screen coordinates to
  12.                       initialize it, then with no parameters to update it.
  13.                       Static variables are used to keep track of screen
  14.                       coordinates and step value.  Called from Main().
  15.  */
  16.  /*
  17.     Modified yo work with the standard DBFNTX RDD.  Modifeid version
  18.     requires NTXPOS from the ClipNet archive NTX2.ARJ.
  19.  */
  20.  FUNC ShowScrollBar( pArray , lDisplay )
  21.  // parameter is an array of nTop, nLeft, nBottom, nRight
  22.  
  23.      static nBarTop, nBarLeft, nBarBottom, nBarRight, nBarWidth
  24.      static nKeyStep, nKeys
  25.      LOCAL  nPos
  26.      LOCAL i
  27.      LOCAL keyno
  28.      LOCAL aReturn := { nBarTop , nBarLeft , nBarBottom , nBarRight }
  29.      LOCAL nHere
  30.      // Did we get coordinates?
  31.      IF pArray # NIL
  32.          // Yes, initialize...
  33.  
  34.          // Set the bar coordinates
  35.          nBarTop    := pArray[1] //nTop
  36.          nBarLeft   := pArray[2] //nLeft
  37.          nBarBottom := pArray[3] //nBottom
  38.          nBarRight  := pArray[4] //nRight
  39.          nBarWidth  := (nBarRight - nBarLeft) + 1
  40.      ENDIF
  41.  
  42.      // default is to display the scroll bar
  43.      If lDisplay = NIL .or. lDisplay
  44.  
  45.          // Get number of keys in current index
  46.          // nKeys    := Sx_KeyCount()
  47.          // Counting records with NTX is a PITA
  48.          nKeys := 0                  // Can handle the new NTX RDD
  49.          nHere := recno()
  50.          dbeval( {|| nKeys := nKeys + 1 } )
  51.          dbGoTo( nHere )              // Leave the dB as I found it
  52.          // Calculate the number of keys to skip before moving "elevator"
  53.          If nKeys < (nBarBottom - nBarTop )
  54.             nKeyStep := INT((nBarBottom - nBarTop) / nKeys )
  55.          Else
  56.             nKeyStep := INT(nKeys / (nBarBottom - nBarTop))
  57.          Endif
  58.          nKeyStep := If(nKeyStep = 0 , 1 , nKeyStep)
  59.  
  60.         // Clear the scroll bar
  61.         For i = nBarTop to nBarBottom
  62.            @ i,nBarLeft SAY REPLICATE(Chr(176),nBarWidth) color clr4
  63.         Next
  64.  
  65.         // Draw the "elevator"
  66.         // keyno := Sx_Keyno()
  67.         keyno := NTXPOS( IndexOrd(), RECNO() )     // For 5.01a
  68.         /*
  69.           The location of the index file handle has been moved in the
  70.           undocumented internal workspace in 5.2.
  71.         */
  72.  *       keyno := NTXPOS( IndexOrd() + 2, RECNO() )     // For 5.2a
  73.         If keyno = 1
  74.           nPos := nBartop
  75.         Elseif keyno = nKeys
  76.           nPos := nBarBottom
  77.         Elseif nKeys < (nBarBottom - nBarTop )
  78.            nPos := MIN(nBarTop + ( (keyno - 1) * nKeyStep), nBarBottom)
  79.         Else
  80.            nPos := MIN(nBarTop + (  keyno / nKeyStep), nBarBottom)
  81.         Endif
  82.         @ nPos,nBarLeft SAY REPLICATE(chr(254),nBarWidth) Color clr4
  83.  
  84.      Endif
  85.  RETURN aReturn
  86.  
  87. That way, by commenting out the line I've marked with "// For 5.01a" and 
  88. including the line I've marked with "// For 5.2a", you can use this same 
  89. function in 5.2a and avoid what appears to be the main VMIEF culprit.
  90.