• Welcome, Guest. Please login.
 
September 17, 2019, 01:54:15 pm

News:

Welcome to the SQLitening support forums!


About slSelArray

Started by Jean-Pierre LEROY, March 20, 2017, 02:41:22 pm

Previous topic - Next topic

cj

March 29, 2017, 11:29:04 am #15 Last Edit: March 29, 2017, 06:20:31 pm by cj
Thank you Bern Ertl!  We now have a fast function to create arrays in column order from an array in row order.

An example using the code extended to formatted files on disk  http://sqlitening.com/support/index.php?topic=9656.0

Quote
You don't need to REDIM the destination array twice.  The code I added to the function call manually resets the string pointers to make that array safe to REDIM.  You added a REDIM to the array outside of the function before the array was made safe to REDIM and thus erasing all the string data (which the source array is still pointing at).  That will cause a GPF the next time a string in the source array is referenced.

The function, as written in my last post, will already redimension the destination array as needed.  The destination array should be considered "read-only" outside of the function (ie. safe to pass data to the grid control, but not for new assignments, clearing or redimensioning).



FUNCTION ReverseDimensions(sSourceArray() AS STRING,sDestArray() AS STRING) AS LONG

'NOTE: Do not REDIM sDestArray() before/after calling to prevent corrupting SourceArray()

LOCAL lpSource AS LONG PTR
LOCAL lpDest   AS LONG PTR
LOCAL COL,ROW,lCol,lRow,uCol,uRow,Cols,Rows AS LONG

lCol = LBOUND(sDestArray,2)
UCol = UBOUND(sDestArray,2)
LRow = LBOUND(sDestArray,1)
URow = UBOUND(sDestArray,1)

rows = UROW-LRow '0 based number of rows
cols = UCOL-lCol '0 based number of columns

lpDest   = VARPTR(sDestArray  (lRow,lCol)) 'first element of destinstion array
FOR ROW = 0 TO rows
  FOR COL = 0 TO cols
   @lpDest[ROW OF rows , COL OF cols] = 0
  NEXT COL
NEXT ROW

lCol = LBOUND(sSourceArray,1)
UCol = UBOUND(sSourceArray,1)
LRow = LBOUND(sSourceArray,2)
URow = UBOUND(sSourceArray,2)

rows = UROW-LRow '0 based number of rows
cols = UCOL-lCol '0 based number of columns

REDIM sDestArray(LRow TO URow,LCol TO UCol) AS STRING

lpSource = VARPTR(sSourceArray(lCol,lRow)) 'first element of source array
lpDest   = VARPTR(sDestArray  (lRow,lCol)) 'first element of destinstion array

FOR ROW = 0 TO rows
  FOR COL = 0 TO cols
   @lpDest[ROW OF rows , COL OF cols] = @lpSource[COL OF cols, ROW OF rows]
  NEXT COL
NEXT ROW

END FUNCTION