array types
Phil Davis
revdev at pdslabs.net
Tue Dec 14 20:35:24 EST 2010
Bob is right - LiveCode does not natively know how to handle lines of data as a
set of fixed-length fields, so you have to roll your own field defs and apply
them to each line.
Here is one way:
local sFieldLengths = "5,16,1,3,8,8"
on mouseUp
answer file "Select a text file with fixed-length fields:"
if it = empty then exit to top
put url ("file:" & it) into tData
split tData with CR
repeat for each key tLineNum in tData
put mySplit(tData[tLineNum]) into tData[tLineNum]
end repeat
-- now 'tData' is a two-dimension array
-- of fields by number within lines by number
end mouseUp
function mySplit pRecord
put 0 into tOffset
put 0 into x
repeat for each item tLength in sFieldLengths
add 1 to x
put char (tOffset+1) to (tOffset+tLength) of pRecord into tFieldArray[x]
add tLength to tOffset
end repeat
return tFieldArray
end mySplit
But if you have control over the data format and can use tab-delimited data, it
becomes much simpler:
on mouseUp
answer file "Select a tab-delimited text file:"
if it = empty then exit to top
put url ("file:" & it) into tData
split tData with CR
repeat for each key tLineNum in tData
split tData[tLineNum] with tab
end repeat
-- now 'tData' is a two-dimension array
-- of fields by number within lines by number
end mouseUp
Food for thought...
Phil Davis
On 12/14/10 3:42 PM, Bob Sneidar wrote:
> Looks like you have to roll your own.
>
> Bob
>
>
> On Dec 14, 2010, at 3:37 PM, JosepM wrote:
>
>> Hi,
>>
>> Is posible in LiveCode delimite the chars of a variable inside of one array
>> to assign other variable that assign the values into the array to each
>> element.
>>
>> Example, so my explanation is confused :) I know.
>>
>> I have a string with:
>>
>> 00000Description nameT001 0.00 0.00
>>
>> and I need to asign the entire string to the array but autofilling the
>> values like in Pascal when use "Type of"
>>
>> So the string will be... splited by the definition of the array, but I don't
>> know if is posible define one array with the length of her elements.
>>
>> 00000
>> Description name
>> T
>> 001
>> 0.00
>> 0.00
>>
>>
>> Salut,
>> Josep
>>
>> --
>> View this message in context: http://runtime-revolution.278305.n4.nabble.com/array-types-tp3088217p3088217.html
>> Sent from the Revolution - User mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
--
Phil Davis
PDS Labs
Professional Software Development
http://pdslabs.net
More information about the use-livecode
mailing list