On Aug 14, 2019, at 9:52 AM, David Short <davy...@gmail.com> wrote:
I can't see that this topic has been addressed before, but I am having a lot of trouble trying to get a script to work that will import a .csv file (from FileMaker) into a stack. ideally it should be able to go through each line of the file and put each item in the line into a new fld and then create a new card fro the next line. Anyone have a successful script?
--
You received this message because you are subscribed to the Google Groups "SuperCard Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supercard-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/supercard-talk/0b2e4344-f3c1-407a-919f-ac5b27aa29a2%40googlegroups.com.
on mouseUp
answer file "Select a file to import:" with extension "csv"
if it = "" then exit script
local inPath = it, outFile = outPath(inPath)
ask file "Save imported data as:" with outFile
if it = "" then exit script
put it into outPath
open file inPath
read from file inPath until eof
close file inPath
if it = "" then exit script
local inData = line 2 to 999999999 of it, fldNames = first line of it, labelRect = "10,10,160,24", fldRect = "150,9,600,29", bump = 24, numFields = the num of items of fldNames, i = 0
new inv proj outPath
set the style of this wd to scrolling
set the editBG to true
set the showFill to false
lock screen
lock messages
set cursor to busy
repeat for each item aName of fldNames
put value(aName) into fldName
set the showpen to false
choose draw text tool
drag from item 1 to 2 of labelRect to item 3 to 4 of labelRect
choose browse tool
set the textData of last bg part to fldName & ":"
set the textColor of last bg part to 256
set the showpen to true
new fld
set the rect of last bg part to fldRect
add 1 to i
if i = numFields then exit repeat
add bump to item 2 of labelRect
add bump to item 4 of labelRect
add bump to item 2 of fldRect
add bump to item 4 of fldRect
end repeat
local newSize = item 3 of fldRect + 10 & comma & item 4 of fldRect + 10, numRecs = the num of lines of inData, recNum = 0
set the backsize of this bg to newSize
add 15 to item 1 of newSize
add 15 to item 2 of newSize
set the windowSize of this wd to newSize
center this wd
set the wordDel to comma
repeat for each line aRecord of inData
add 1 to recNum
put 1 into fldNum
repeat for each word aField of aRecord
put value (aField) into bg fld fldNum
add 1 to fldNum
end repeat
if recNum < numRecs then new cd
end repeat
set the itemDel to ":"
set the name of this wd to last item of inPath
open cd 1 of this wd
put merge("[[numRecs]] records consisting of [[numFields]] fields each successfully imported")
end mouseUp
function outPath inPath
set the itemDel to ":"
set the wordDel to "."
return first word of last item of inPath & ".sc45"
end outPath
set the name of last bg part to fldName & "_label"
set the textData of last bg part to fldName & ":"
set the textColor of last bg part to 256
set the showpen to true
new fld
set the rect of last bg part to fldRect
set the name of last bg part to fldName
add 1 to i
if i = numFields then exit repeat
add bump to item 2 of labelRect
add bump to item 4 of labelRect
add bump to item 2 of fldRect
add bump to item 4 of fldRect
end repeat
local newSize = item 3 of fldRect + 10 & comma & item 4 of fldRect + 10, numRecs = the num of lines of inData, recNum = 0
set the backsize of this bg to newSize
add 15 to item 1 of newSize
add 15 to item 2 of newSize
set the windowSize of this wd to newSize
center this wd
set the wordDel to comma
repeat for each line aRecord of inData
add 1 to recNum
put 1 into fldNum
repeat for each word aField of aRecord
set the text of bg fld fldNum to value(aField)
add 1 to fldNum
end repeat
if recNum < numRecs then new cd
end repeat
set the itemDel to ":"
set the name of this wd to last item of inPath
open cd 1 of this wd
put merge("[[numRecs]] records consisting of [[numFields]] fields each successfully imported")
end mouseUp
function outPath inPath
set the itemDel to ":"
set the wordDel to "."
return first word of last item of inPath & ".sc45"
end outPath
on mouseUp
answer file "Select a file to import:" with extension "csv"
if it = "" then exit script
local inPath = it, outFile = outPath(inPath)
ask file "Save imported data as:" with outFile
if it = "" then exit script
put it into outPath
open file inPath
read from file inPath until eof
close file inPath
if it = "" then exit script
set cursor to watch
lock messages
local fldNames = first line of it, labelRect = "10,10,140,24", fieldRect = "150,9,600,29", bump = 24, numFields = the num of items of fldNames, i = 0
delete first line of it
new inv proj outPath
lock screen
set the editBG to true
set the showFill to false
repeat for each item aName of fldNames
put value(aName) into fldName
set the showpen to false
choose draw text tool
drag from item 1 to 2 of labelRect to item 3 to 4 of labelRect
choose browse tool
set the name of last bg part to fldName & "_label"
set the textData of last bg part to fldName & ":"
set the textColor of last bg part to 256
set the showpen to true
new fld
set the rect of last bg part to fieldRect
set the name of last bg part to fldName
add 1 to i
if i = numFields then exit repeat
put offsetRect(labelRect, 0, bump) into labelRect
put offsetRect(fieldRect, 0, bump) into fieldRect
end repeat
local newSize = item 3 of fieldRect + 10 & comma & item 4 of fieldRect + 10, numRecs = the num of lines of it, recNum = 0
set the backsize of this bg to newSize
set the windowSize of this wd to item 1 of newSize + 15, item 2 of newSize + 15
center this wd
set the wordDel to comma
repeat for each line aRecord of it
add 1 to recNum
put 1 into fldNum
repeat for each word aField of aRecord
set the text of bg fld fldNum to value(aField)
add 1 to fldNum
end repeat
if recNum < numRecs then new cd
end repeat
set the itemDel to ":"
set the name of this wd to last item of inPath
set the style of this wd to scrolling
open cd 1 of this wd
put merge("[[numRecs]] records consisting of [[numFields]] fields each successfully imported")
end mouseUp
function outPath inPath
set the itemDel to ":"
set the wordDel to "."
return first word of last item of inPath & ".sc45"
--
You received this message because you are subscribed to the Google Groups "SuperCard Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supercard-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/supercard-talk/30e0d221-5150-4eda-aac2-feae4fc58a99%40googlegroups.com.
I see you use the local keyword. Is this simply a technique or style that you use.
Also, if this was a very large file to imported would the free size become an issue. And if so how you handle that?
if recNum mod 100 = 0 then put recNum && "of" && numRecs
On Aug 15, 2019, at 10:17 AM, 'codegreen' via SuperCard Discussion <superca...@googlegroups.com> wrote:
On Thursday, August 15, 2019 at 12:13:01 PM UTC-4, Bill Bowling wrote:I see you use the local keyword. Is this simply a technique or style that you use.Just a personal preference. Horizontal space is easier to come by than vertical when editing scripts nowadays, so glomming together multiple variable declarations and assignments on a single line lets me see more of the actual program logic at once than if each occupied a separate line.Also, if this was a very large file to imported would the free size become an issue. And if so how you handle that?Do you mean free space in the target project? If so, there shouldn't be any. FWIW I just ran this script on a CSV file with fifty thousand records in it, and the created project had no free space when the script completed. BTW if you're planning on importing whopping huge files you'll probably want to stick a progress message of some sort down at the bottom of the main record import loop:if recNum mod 100 = 0 then put recNum && "of" && numRecs
Or do you mean RAM to hold the csv data in? If so, then you could just read it in smaller fixed-size chunks (trimming off the slop from any partial trailing record and either prepending it to the data from the following read or backing up the file read offset by its length).
Does that make sense?-Mark
--
You received this message because you are subscribed to the Google Groups "SuperCard Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supercard-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/supercard-talk/9627db16-91cd-4663-bf70-a1d18b850d61%40googlegroups.com.
I have an older project (5gb) that has about a 100 cards. Each of those cards has 3 bg flds that hold 6.6 mb each. This project will search for an employee id for each card card (bid month) and assemble a roster for each month. Needless to say for every month (or card) i’m replacing my 3 6.6mb variables and replacing the completed output into a bg fld. I do take the data fields and put them in variables as this improves speed.I have had problems in the past with this project getting slow or crashing. To resolve this I added a trap in the repeat loop that sends a mouseup to “parse data” button of every card to check for the freesize and compact if the value is above a certain value. This resulted in spinning beach balls … so now I just compact on every repeat.
diskutil erasevolume HFS+ “RAMDisk” `hdiutil attach -nomount ram://16777216`
--
You received this message because you are subscribed to the Google Groups "SuperCard Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supercard-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/supercard-talk/db3a7f04-8dfc-4850-835f-dfc5c2453824%40googlegroups.com.
If you can, compact only at the very end. File formats like SuperCard's
generally re-use free space in a file, so if you compact on every
repeat, you're closing the gaps that SuperCard would have re-used,
forcing SuperCard to move huge chunks of data around on every repeat,
instead of only once at the end.
--
You received this message because you are subscribed to the Google Groups "SuperCard Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supercard-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/supercard-talk/dd387fb5-35c2-4f36-9a17-670c786ec703%40googlegroups.com.