Search content:

 

Personal Menu
Username:
Password:
Save password

Become a member

Forgot Password?

 

Don't miss these
Add/Remove Line Feeds
Flash Sprite -- Simple Controller [Play, Pause, Rewind]
cXtraStringGrid
Navegacion y colision 3d - 3d Collision Navigation
Fast Start Projector
Odd levels cause audio to play incorrectly
FlashMaster
China Multimedia Union
cXtraCD
Browse Folders Dialog Behavior
MediaMacros Xtras Mall
 

 

 

Behavior Creating an object that simulates an array

Added on 7/2/1999

 

Compatibilities:
D6_5 D7 D8 Mac PC Script

This item has not yet been rated

Author: Penworks (website)

Reproduced with permission from Penworks Lingo User"s Journal

-- Source Code from the Lingo User"s Journal
-- Copyright (c) 1995 by Penworks Corporation

-- Array Script

property iFirstRow  -- lower row bound
property iLastRow   -- upper row bound
property inRows      -- number of rows
property iFirstCol   -- lower column bound
property iLastCol    -- upper column bound
property iInitialValue -- initial value (for initialization)
property inCols       -- number of columns, (saved for speed)
property iCellList   -- the data of the array
property iRangeCheckFlag  -- flag used for debugging


-- Create the array passing the row and column lower and upper
-- bounds and an initial value
on birth me, firstRow, lastRow, firstCol, lastCol, initialValue
  set iFirstRow = firstRow
  set iLastRow = lastRow
  set inRows = iLastRow - iFirstRow + 1
  set iFirstCol = firstCol
  set iLastCol = lastCol
  set iInitialValue = initialValue
  set inCols = iLastCol - iFirstCol + 1
  set inCells = inRows * inCols
-- Create the actual array as a list
  set iCellList = []
  repeat with i = 1 to inCells
    add(iCellList, initialValue)
  end repeat
  set iRangeCheckFlag = FALSE
  return me
end birth


-- Used to set the value of one cell in the array
on mSet me, theRow, theCol, theValue
  if iRangeCheckFlag then
    if (theRow < iFirstRow) or (theRow > iLastRow) then
      alert("Invalid row index to mSet, value is:" && theRow & RETURN & ...
               "Valid values are from"  && iFirstRow && "to" && iLastRow)
      exit
    end if
    if (theCol < iFirstCol) or (theCol > iLastCol) then
      alert("Invalid column index to mSet, value is:" && theCol & RETURN &
...
               "Valid values are from"  && iFirstCol && "to" && iLastCol)
      exit
    end if
  end if
  
  set theCell = ((theRow - iFirstRow) * inCols) + (theCol - iFirstCol) + 1
  setAt(iCellList, theCell, theValue)
end mSet

-- Used to get the value of one cell in the array
on mGet me, theRow, theCol
  if iRangeCheckFlag then
    if (theRow < iFirstRow) or (theRow > iLastRow) then
      alert("Invalid row index to mGet, value is:" && theRow & RETURN &...
               "Valid values are from"  && iFirstRow && "to" && iLastRow)
      exit
    end if
    if (theCol < iFirstCol) or (theCol > iLastCol) then
      alert("Invalid column index to mGet, value is:" && theCol & RETURN ...
               "Valid values are from"  && iFirstCol && "to" && iLastCol)
      exit
    end if
  end if
  
  set theCell = ((theRow - iFirstRow) * inCols) + (theCol - iFirstCol) + 1
  return getAt(iCellList, theCell)
end mGet

-- Used to turn on or off range checking
on mSetRangeChecking me, trueOrFalse
  set iRangeCheckFlag = trueOrFalse
end mSetRangeChecking


-- Give back memory before disposing of the array object
on mCleanup me
  set iCellList = []
end mCleanup

-- Resets the value of all cells to the initial value
on mReInitialize me
  repeat with thisCell = 1 to inCells
    setAt(iCellList, thisCell, initialValue)
  end repeat
end mReInitialize

-- Prints the contents of the array to the message window
on mDebug me
  repeat with i = iFirstRow to iLastRow
    set thisRow = ""
    repeat with j = iFirstCol to iLastCol
      set thisRow = thisRow && mGet(me, i, j)
    end repeat
    put thisRow
  end repeat  
end mDebug

 


Upload Provided by ABCUpload ASP

Contact

MMI
22 West Court Sq
Suite 2C
Newnan, GA 30263
USA

Fax - (206) 339-5833

Send e-mail