Building an EXE -- need help
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Building an EXE -- need help
Hi community,
I want to build a simple, lightweight program that does 1 thing only. Let me illustrate that thing.
Basically, I have **lots of individual data files** that have various different lines in them (for example):
TrialType1, [bunch of data out here]
TrialType2, [bunch of data out here]
The first item in each line denotes the kind of trial. I want the program to combine all my data files based solely on the first item of each line, while also keeping track of which file the data came from (for example):
File1,TrialType1, [bunch of data out here] <------ All Trial Type "1s" will be in the first file
File2,TrialType1, [bunch of data out here]
...and in a separate output file
File1, TrialType2, [bunch of data out here] <------ All Trial Type "2s" will be in the second file
File2, TrialType2, [bunch of data out here]
Thanks!
I want to build a simple, lightweight program that does 1 thing only. Let me illustrate that thing.
Basically, I have **lots of individual data files** that have various different lines in them (for example):
TrialType1, [bunch of data out here]
TrialType2, [bunch of data out here]
The first item in each line denotes the kind of trial. I want the program to combine all my data files based solely on the first item of each line, while also keeping track of which file the data came from (for example):
File1,TrialType1, [bunch of data out here] <------ All Trial Type "1s" will be in the first file
File2,TrialType1, [bunch of data out here]
...and in a separate output file
File1, TrialType2, [bunch of data out here] <------ All Trial Type "2s" will be in the second file
File2, TrialType2, [bunch of data out here]
Thanks!
Last edited by PoLyGLoT on Mon Dec 22, 2014 5:55 am, edited 1 time in total.
Re: Building an EXE -- need help
Hi all,
I've figured out a great portion of what I want to do. I can reference a folder, have it list filenames in that folder, have it open those files, have it put the appropriate prefix before each line, have it combine all my files with this rule, and have it write that information to a text file on the desktop.
Rejoice - for a great deal of my task is accomplished!
However, I still want to do one critical thing: Split my files by item 1 of each line. Let me give an example.
If I have 8 different "item 1" values, I want all corresponding item 1 values to be placed in their own unique file on the desktop. For example, "Combined Files 1" = item type 1, "Combined Files 2" = item type 2, etc.
I've figured out a great portion of what I want to do. I can reference a folder, have it list filenames in that folder, have it open those files, have it put the appropriate prefix before each line, have it combine all my files with this rule, and have it write that information to a text file on the desktop.
Rejoice - for a great deal of my task is accomplished!
However, I still want to do one critical thing: Split my files by item 1 of each line. Let me give an example.
If I have 8 different "item 1" values, I want all corresponding item 1 values to be placed in their own unique file on the desktop. For example, "Combined Files 1" = item type 1, "Combined Files 2" = item type 2, etc.
Re: Building an EXE -- need help
Another critical hurdle accomplished:
I've figured out a way to store only the unique trial types (i.e., item 1 of each line) in "bin". For example, I've listed each separate trial type in bin, and then removed all the duplicates. This left me, in one case, with only four lines in bin (4 separate trial types).
Now: I need the program to automatically put lines of data into separate bins if they match on of those lines in bin.
For example: If in one case, I have 7 unique types of trials (and 7 lines in bin), I need it to automatically create 7 new bin variables and place the corresponding trial types for all files in those bins. It needs to use previously created bins if it's a match, and create a new bin if no other bins are currently housing similar trial types.
I've figured out a way to store only the unique trial types (i.e., item 1 of each line) in "bin". For example, I've listed each separate trial type in bin, and then removed all the duplicates. This left me, in one case, with only four lines in bin (4 separate trial types).
Now: I need the program to automatically put lines of data into separate bins if they match on of those lines in bin.
For example: If in one case, I have 7 unique types of trials (and 7 lines in bin), I need it to automatically create 7 new bin variables and place the corresponding trial types for all files in those bins. It needs to use previously created bins if it's a match, and create a new bin if no other bins are currently housing similar trial types.
Re: Building an EXE -- need help
Final riddle, and I've got it (I think):
Bin looks like this:
I want to automatically create separate bins called bin1,bin2,bin3,bin4, etc. (depending on num lines in "bin")
I'm trying code like this:
I want it to create those bins automatically. Later, I can reference the first item of each bin to put the appropriate lines of data after them.
Bin looks like this:
Code: Select all
test
study
1
pre-exposure
I'm trying code like this:
Code: Select all
repeat with z = 1 to the num of lines in bin
put item 1 of line 1 of bin into item 1 of line 1 of bin[z] <--- for illustrative purposes, need this to advance numerically (z)
end repeat
Re: Building an EXE -- need help
This code is working exactly as I want:
However, the code is overly long and I'd like the ability to use a repeat loop that could go out to as many bins as needed if "item 1" keeps differing (usually at most 10 or 15, but I'd go 100 times to be safe).
Code: Select all
put empty into bin1
put empty into bin2
put empty into bin3
put empty into bin4
repeat for each line tLine in it
put item 1 of tLine into item1
if bin1 is empty then
put tLine & return after bin1
else
if item1 = item 1 of line 1 of bin1 then
put tLine & return after bin1
else
if bin2 is empty then
put tLine & return after bin2
else
if item1 = item 1 of line 1 of bin2 then
put tLine & return after bin2
else
if bin3 is empty then
put tLine & return after bin3
else
if item1 = item 1 of line 1 of bin3 then
put tLine & return after bin3
else
put tLine & return after bin4
end if
end if
end if
end if
end if
end if
end repeat
Re: Building an EXE -- need help
I work with arrays a lot. When I need to increment through them in a repeat loop, I use "do" like this
Code: Select all
repeat with z = 1 to the num of lines in bin
do "put item 1 of line 1 of bin into item 1 of line 1 of bin["&z&"]"
end repeat
Re: Building an EXE -- need help
Magice,
Thank you very much for responding. I was trying to use a similar code (with an array and a do statement), but couldn't get it to work.
I will try your code and keep you updated!
Assuming your code works, is there any way to get the individual lines to automatically be placed in their appropriate bins?
For example, imagine mArray looks like this:
study: 48
test: 322
pre-exposure: 96
1: 2
I want the 48 study lines in bin1, the 322 test lines in bin2, etc. Any easy way to do this? I'll check out your code now..
Thank you very much for responding. I was trying to use a similar code (with an array and a do statement), but couldn't get it to work.
I will try your code and keep you updated!
Assuming your code works, is there any way to get the individual lines to automatically be placed in their appropriate bins?
For example, imagine mArray looks like this:
study: 48
test: 322
pre-exposure: 96
1: 2
I want the 48 study lines in bin1, the 322 test lines in bin2, etc. Any easy way to do this? I'll check out your code now..
Re: Building an EXE -- need help
Success!! I've done it!!
Item 2 now has the "trial type" marker I care about in the code below:
Now I have these arrays:
kArray:
1: 2
pre-exposure: 96
study: 48
test: 388
mArray:
every line of "it" (my data)
bin[1]:
all lines of trial type 1
bin[pre-exposure]:
all lines of trial type "pre-exposure
bin[study]:
all lines of trial type "study"
bin[test]
all lines of trial type "test"
Perfect! Now I just need a way to output those bins and their contents *after* real variables, and keep adding relevant data from all my other files to those bins. I'll figure out a way!
Item 2 now has the "trial type" marker I care about in the code below:
Code: Select all
repeat for each line tLine in it
put item 2 of line 1 of tLine into TrialTypes
add 1 to mArray[tLine]
add 1 to kArray[TrialTypes]
end repeat
repeat for each key mKey in mArray
repeat for each key kKey in kArray
if item 2 of mKey = item 1 of kKey then
put mKey & return after bin[kKey]
end if
end repeat
end repeat
kArray:
1: 2
pre-exposure: 96
study: 48
test: 388
mArray:
every line of "it" (my data)
bin[1]:
all lines of trial type 1
bin[pre-exposure]:
all lines of trial type "pre-exposure
bin[study]:
all lines of trial type "study"
bin[test]
all lines of trial type "test"
Perfect! Now I just need a way to output those bins and their contents *after* real variables, and keep adding relevant data from all my other files to those bins. I'll figure out a way!
Re: Building an EXE -- need help
Success in translating an Array into automatically numbered bins!
Code: Select all
repeat for each key bKey in bin
add 1 to z
do "put bin[bKey] & return after bin" & z
end repeat
Re: Building an EXE -- need help
Hi Polyglott,
yep, DO is the only thing that will DO this!
But I am wondering why you need these variables since you can always
use and address this array the same way, if you make it global (or local)?
This (uisng an ARRAY) is actually the workaround most LC developers use in situations like this,
instead of using DO to create single variables from the keys of an array!
Best
Klaus
yep, DO is the only thing that will DO this!

But I am wondering why you need these variables since you can always
use and address this array the same way, if you make it global (or local)?
This (uisng an ARRAY) is actually the workaround most LC developers use in situations like this,
instead of using DO to create single variables from the keys of an array!

Best
Klaus
Re: Building an EXE -- need help
If you find yourself using the do command a lot, the quotation marks can get a bit confusing, especially when you actually need quotation marks within the statement and have to write out ""e&". A while back Simon posted a great tool he wrote to help with this. Just do a search on this forum for "Pesky Quotes". I can't tell you how helpful it has been for me.
Re: Building an EXE -- need help
Do you mean the q function(s)?
Code: Select all
## Double quote -> "
function q tString
return QUOTE & tString & QUOTE
end q
## Single quote -> '
## Useful when creating database SQL strings
function q2 tString
return "'" & tString & "'"
end q2
Re: Building an EXE -- need help
Actually no, I meant his app "Infamous Quotes". Basically you feed the command you want the do command to perform into his app, and it outputs the line with all quotation marks and "quote" constants in place.Klaus wrote:Do you mean the q function(s)?Code: Select all
## Double quote -> " function q tString return QUOTE & tString & QUOTE end q ## Single quote -> ' ## Useful when creating database SQL strings function q2 tString return "'" & tString & "'" end q2
Re: Building an EXE -- need help
Ah, OK, sorry, no idea 

Re: Building an EXE -- need help
Hi Klaus,Klaus wrote:Hi Polyglott,
yep, DO is the only thing that will DO this!![]()
But I am wondering why you need these variables since you can always
use and address this array the same way, if you make it global (or local)?
This (uisng an ARRAY) is actually the workaround most LC developers use in situations like this,
instead of using DO to create single variables from the keys of an array!![]()
Best
Klaus
This is all an adventure for me. You may be right - I could not need to create the separate bins.
My goal (which I've almost accomplished) was this:
1) Use arrays to quickly split my data based on trial type
2) Generate separate bin variables for each trial type
3) Write those files to the desktop
4) Import those files into excel, where I can do further analyses using other functions (e.g., pivot tables)
I have lots of different data files that use different kinds of trial types. I want to create 1 program that can work for all my data, so that if I load in a batch of data, I'll always get the same kind of output files split up by trial type. It's gonna be so awesome!