loading an array from an external text file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

loading an array from an external text file

Post by magice » Mon Mar 23, 2009 1:01 am

I have figured out (thanks to a search of these forums) how to save a combined array to a text file. Now, I need to know how to make an "open" dialog box pop up, and how to read the data in a chosen text file and put it back into a variable for splitting. any help would be greatly appreciated

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Mar 23, 2009 7:23 am

This can be as simple as

Code: Select all

on mouseUp
  local tFilePath, tData, tLine, tItem
  local tArray, tRowCounter, tColumnCounter
  answer file "Open tab-delimited text file"
  if it is empty then exit mouseUp
  put it into tFilePath
  put URL ("file:" & tFilePath) into tData
  put 0 into tRowCounter
  set the itemDelimiter to tab
  repeat for each line tLine in tData
    add 1 to tRowCounter
    put 0 into tColumnCounter
    repeat for each item tItem in tLine
      add 1 to tColumnCounter
      put tItem into tArray[tRowCounter,tColumnCounter]
    end repeat
  end repeat
end mouseUp
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Mon Mar 23, 2009 7:42 am

Stacks are files too, and natively support arrays in custom properties.

You can save yourself some parsing time by just using stack files for you file format:

set the customProperties of tMyDataStack to MyArray
put the customProperties o tMyDataStack into tMyArray
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply