desktop and standalone
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 151
- Joined: Sat Aug 25, 2012 1:14 am
desktop and standalone
this codes works great when I'm one the desktop. But doesn't as a standalone. I've used documents and engine.
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp" & "/Receipt.txt") into tSavedFile.
I check for the file at startup of the app. I know it's something simple but I just can't see it.
Thank you
Ty
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp" & "/Receipt.txt") into tSavedFile.
I check for the file at startup of the app. I know it's something simple but I just can't see it.
Thank you
Ty
-
- VIP Livecode Opensource Backer
- Posts: 9679
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: desktop and standalone
Hi..
Um, which code was that?
And standalones may require inclusions, that if omitted will break things. We need to know more...
Craig
Um, which code was that?
And standalones may require inclusions, that if omitted will break things. We need to know more...
Craig
-
- Posts: 151
- Joined: Sat Aug 25, 2012 1:14 am
Re: desktop and standalone
on preOpenCard
local tToDoList, tCarNotes, tNotename, tCarNote, tNoteTime, tCarBuild, tTry,tName,tToDolistDataArray,tDGLines,tSavedFile
local tSavedFile2
set the itemDelimiter to tab
set the itemDelimiter to tab
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp" & "/Receipt.txt") into tSavedFile
repeat with x = 1 to the number of lines of tSavedFile
put item 1 of line x of tSavedFile into item 1 of line x of tName
put item 2 of line x of tSavedFile into item 2 of line x of tName
put item 3 of line x of tSavedFile into item 3 of line x of tName
put item 4 of line x of tSavedFile into item 4 of line x of tName
put item 5 of line x of tSavedFile into item 5 of line x of tName
put item 6 of line x of tSavedFile into item 6 of line x of tName
put item 7 of line x of tSavedFile into item 7 of line x of tName
put item 9 of line x of tSavedFile into item 9 of line x of tName
put item 10 of line x of tSavedFile into item 10 of line x of tName
end repeat
repeat with x = 1 to tLines
put item 1 of line x of tName into tToDolistDataArray[X]["Create Date"]
put item 2 of line x of tName into tToDolistDataArray[X]["Date"]
put item 3 of line x of tName into tToDolistDataArray[X]["Store"]
put item 4 of line x of tName into tToDolistDataArray[X]["Category"]
put item 5 of line x of tName into tToDolistDataArray[X]["CDate2"]
put item 6 of line x of tName into tToDolistDataArray[X]["Cost"]
--put item 7 of line x of tName into tToDolistDataArray[X]["img"]
put item 9 of line x of tName into tToDolistDataArray[X]["Taxes Paid"]
put item 10 of line x of tName into tToDolistDataArray[X]["Image"]
end repeat
set the dgData of group "dgReceipt" of me to tToDolistDataArray
I hope this helps, it's overkill maybe.
Thank you
Ty
local tToDoList, tCarNotes, tNotename, tCarNote, tNoteTime, tCarBuild, tTry,tName,tToDolistDataArray,tDGLines,tSavedFile
local tSavedFile2
set the itemDelimiter to tab
set the itemDelimiter to tab
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp" & "/Receipt.txt") into tSavedFile
repeat with x = 1 to the number of lines of tSavedFile
put item 1 of line x of tSavedFile into item 1 of line x of tName
put item 2 of line x of tSavedFile into item 2 of line x of tName
put item 3 of line x of tSavedFile into item 3 of line x of tName
put item 4 of line x of tSavedFile into item 4 of line x of tName
put item 5 of line x of tSavedFile into item 5 of line x of tName
put item 6 of line x of tSavedFile into item 6 of line x of tName
put item 7 of line x of tSavedFile into item 7 of line x of tName
put item 9 of line x of tSavedFile into item 9 of line x of tName
put item 10 of line x of tSavedFile into item 10 of line x of tName
end repeat
repeat with x = 1 to tLines
put item 1 of line x of tName into tToDolistDataArray[X]["Create Date"]
put item 2 of line x of tName into tToDolistDataArray[X]["Date"]
put item 3 of line x of tName into tToDolistDataArray[X]["Store"]
put item 4 of line x of tName into tToDolistDataArray[X]["Category"]
put item 5 of line x of tName into tToDolistDataArray[X]["CDate2"]
put item 6 of line x of tName into tToDolistDataArray[X]["Cost"]
--put item 7 of line x of tName into tToDolistDataArray[X]["img"]
put item 9 of line x of tName into tToDolistDataArray[X]["Taxes Paid"]
put item 10 of line x of tName into tToDolistDataArray[X]["Image"]
end repeat
set the dgData of group "dgReceipt" of me to tToDolistDataArray
I hope this helps, it's overkill maybe.
Thank you
Ty
-
- VIP Livecode Opensource Backer
- Posts: 9679
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: desktop and standalone
Hi.
A couple of things.
First, it does not seem, if that is the entirety of your scripts, that anything in them ought to affect a standalone as opposed to working in the IDE. That assumes, however, that the "datagrid" inclusion is selected in the standalone settings.
Second, this, for example:
could be shortened a bit:
But that is another subject entirely, to streamline your coding generally. We are here for just that sort of thing.
So going back to the standalone thing, do you have that inclusion?
Craig
A couple of things.
First, it does not seem, if that is the entirety of your scripts, that anything in them ought to affect a standalone as opposed to working in the IDE. That assumes, however, that the "datagrid" inclusion is selected in the standalone settings.
Second, this, for example:
Code: Select all
repeat with x = 1 to the number of lines of tSavedFile
put item 1 of line x of tSavedFile into item 1 of line x of tName
put item 2 of line x of tSavedFile into item 2 of line x of tName
put item 3 of line x of tSavedFile into item 3 of line x of tName
put item 4 of line x of tSavedFile into item 4 of line x of tName
put item 5 of line x of tSavedFile into item 5 of line x of tName
put item 6 of line x of tSavedFile into item 6 of line x of tName
put item 7 of line x of tSavedFile into item 7 of line x of tName
put item 9 of line x of tSavedFile into item 9 of line x of tName
put item 10 of line x of tSavedFile into item 10 of line x of tName
end repeat
Code: Select all
repeat with x = 1 to the number of lines of tSavedFile
put item x of line x of tSavedFile into item x of line x of tName
end repeat
So going back to the standalone thing, do you have that inclusion?
Craig
Re: desktop and standalone
I might be wrong, but your code would only work if the number of items = the number of lines, which is probably not the casedunbarx wrote: ↑Thu Jul 07, 2022 2:36 amcould be shortened a bit:But that is another subject entirely, to streamline your coding generally. We are here for just that sort of thing.Code: Select all
repeat with x = 1 to the number of lines of tSavedFile put item x of line x of tSavedFile into item x of line x of tName end repeat
So going back to the standalone thing, do you have that inclusion?
Craig
You need a nested loop (1 to run through the lines and 1 to run through the items).
There are some other issues with the OP's code. For example tLines is not declared or assigned a value, yet a loop is being run to it.
The reason the OP's code isn't working is probably the line:
Code: Select all
repeat with x = 1 to tLines
I also can't see why you'd have the intermediary tName and not just assign the value direct to an array.
Also you can shorten the code by assigning key names through a variable.
This is my take on it and although completely untested, it should do what the OP intends:
Code: Select all
on preOpenCard
local tToDolistDataArray, tSavedFile, x, tKeyNames
set the itemDelimiter to tab
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp/Receipt.txt") into tSavedFile -- removed unnecessary '&'
put "Create Date,Date,Store,Category,CDate2,Cost,img,Taxes Paid,image" into tKeyNames - the array's key names (NOTE: no space after comma!)
set the itemDelimiter to comma
repeat for each line tLine in tSavedFile
add 1 to x -- 'repeat for each' loops are much much faster than 'repeat with x = 1 to num' loops, but you still need a counter (declared as local var)
repeat with y = 1 to the number of items of tKeyNames
put item y of tLine into tToDolistDataArray[x][item y of tKeyNames]
end repeat
end repeat
set the dgData of group "dgReceipt" of me to tToDolistDataArray
end preOpenCard
Last edited by stam on Thu Jul 07, 2022 10:11 am, edited 5 times in total.
Re: desktop and standalone
On a related note, i wouldn't have that code directly in the preOpenCard handler, but would assign it to it's own handler which is then called via preOpenCard, but can also be used in other contexts, for example is you just want to refresh the data from the text file.
On a less related but perhaps useful note, i also don't assign the data directly to the data grid's dgData, because very frequently i will want to filter data in the data grid (if you're searching for something specific for example).
What i do instead is assign the data to a custom property of the data grid that contains the entire data set and then this can either be assign to the dgData or can be filtered into another array to be assigned to the dgData of the data grid.
Ie, the last line of the handler in my apps will usually be something like:
then i can filter the allData of the group and assign that to the dgData, eg
This way i can run any number of searches/filtering on the data grid without disturbing the full data set, and can always restore the data to the full data set by simply assigning the dgData to the custom property 'allData' of the data grid...
On a less related but perhaps useful note, i also don't assign the data directly to the data grid's dgData, because very frequently i will want to filter data in the data grid (if you're searching for something specific for example).
What i do instead is assign the data to a custom property of the data grid that contains the entire data set and then this can either be assign to the dgData or can be filtered into another array to be assigned to the dgData of the data grid.
Ie, the last line of the handler in my apps will usually be something like:
Code: Select all
set the allData of group "dgReceipt" to tToDolistDataArray
set the dgData of group "dgReceipt" to the allData of group "dgReceipt"
Code: Select all
put the allData of group "dgReceipt" into tArray
filter elements of tArray where each["<key>"] contains "<search text>"
set the dgData of group "dgReceipt" to tArray
-
- VIP Livecode Opensource Backer
- Posts: 9679
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: desktop and standalone
What Stam says.
I agree that the original offering was set up in such a way that my one liner worked just fine. But it also seemed that the structure itself always had the index used in just that way, regardless of the number of chunks. After all, this was not a general question, but an actual code segment for the tsk at hand. If that changed, then certainly such a radical simplification would not be appropriate. But I really was just making a streamlining point, wanting the OP to see that point.
All this begs the issue about the standalone problem, the only one actually of interest to the OP. Stam, you and I are both off in the weeds.
I like weed.
Craig
I agree that the original offering was set up in such a way that my one liner worked just fine. But it also seemed that the structure itself always had the index used in just that way, regardless of the number of chunks. After all, this was not a general question, but an actual code segment for the tsk at hand. If that changed, then certainly such a radical simplification would not be appropriate. But I really was just making a streamlining point, wanting the OP to see that point.
All this begs the issue about the standalone problem, the only one actually of interest to the OP. Stam, you and I are both off in the weeds.
I like weed.
Craig
Re: desktop and standalone
The original problem was posted as inability to get what works in the IDE to work in the standalone.
I don't disagree with your comment Craig - we may indeed be both off in the weeds, but I can't see that this code should even work in the IDE (see the comment about tLines in my previous post).
breaking down the OP's handler into logical steps:
1. import a delimited text file into a variable
2. convert the deleted text in the variable into an array
3. assign the array to a data grid
Where it looks like it probably falls down is (2) - although without a working stack to step through the code in the debugger, it's difficult to know for sure.
As you say Craig, there is nothing in the code that suggests it shouldn't work in standalone - but i suspect the code might be the problem, not the inclusions.
The posted code benefits from refactoring - while i haven't tested my code it *looks* like it should work, perhaps the OP can feed back... you never know, that may sort the OP's issue.
@tyarmsteadBUSuSfT - if this doesn't fix your issue, can you share a stack (and an example text file) that shows the problem? Stepping through the code in the debugger and looking at the variable values is invaluable in tracking down the issue.
In general though it usually does help to create small stack with only the problem function in it - i do this a lot when trying to debug issues where no answer is evident. That way you minimise interaction with other code that may be causing issues (i've had situations where a LiveCode subsystem has stalled with an error but no error message was generated - but as a result nothing worked); it also helps you focus on the problem at hand.
HTH
Stam
I don't disagree with your comment Craig - we may indeed be both off in the weeds, but I can't see that this code should even work in the IDE (see the comment about tLines in my previous post).
breaking down the OP's handler into logical steps:
1. import a delimited text file into a variable
2. convert the deleted text in the variable into an array
3. assign the array to a data grid
Where it looks like it probably falls down is (2) - although without a working stack to step through the code in the debugger, it's difficult to know for sure.
As you say Craig, there is nothing in the code that suggests it shouldn't work in standalone - but i suspect the code might be the problem, not the inclusions.
The posted code benefits from refactoring - while i haven't tested my code it *looks* like it should work, perhaps the OP can feed back... you never know, that may sort the OP's issue.
@tyarmsteadBUSuSfT - if this doesn't fix your issue, can you share a stack (and an example text file) that shows the problem? Stepping through the code in the debugger and looking at the variable values is invaluable in tracking down the issue.
In general though it usually does help to create small stack with only the problem function in it - i do this a lot when trying to debug issues where no answer is evident. That way you minimise interaction with other code that may be causing issues (i've had situations where a LiveCode subsystem has stalled with an error but no error message was generated - but as a result nothing worked); it also helps you focus on the problem at hand.
HTH
Stam
-
- VIP Livecode Opensource Backer
- Posts: 9679
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: desktop and standalone
What Stam said again.
So tyarmsteadBUSuSfT, I am taking you at your word when you say the stack works in the IDE. Please verify that, so Stam and I can have our inclusions/code battle in peace.
Craig
So tyarmsteadBUSuSfT, I am taking you at your word when you say the stack works in the IDE. Please verify that, so Stam and I can have our inclusions/code battle in peace.
Craig
-
- Posts: 151
- Joined: Sat Aug 25, 2012 1:14 am
Re: desktop and standalone
I tried to attached the stack, but got the error of unsupported file extension.
Ty
Ty
-
- VIP Livecode Opensource Backer
- Posts: 9679
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: desktop and standalone
Was the stack zipped? It has to be.
Craig
Craig
-
- Posts: 151
- Joined: Sat Aug 25, 2012 1:14 am
Re: desktop and standalone
Thank you, I forgot it had to be zipped.
Ty
Ty
- Attachments
-
- TestCarBuild.livecode.zip
- (45.96 KiB) Downloaded 81 times
Re: desktop and standalone
Could you also provide a text file with test data that fits your use case? Difficult to test without that
-
- Posts: 151
- Joined: Sat Aug 25, 2012 1:14 am
Re: desktop and standalone
Please see attached, thank yo
Ty
Ty
- Attachments
-
- Receipt.txt.zip
- (1.06 KiB) Downloaded 85 times
Re: desktop and standalone
Unfortunately my main MBP has a butterfly keyboard and it's lost a couple of keys :-/
So i'm now using a much older MBP which i haven't used in a while and it's taking forever to get Xcode stuff on, so i can't build standalones right now :-/
2 notes:
- both your code and mine (as posted above) work fine in the IDE
- These should work as is on the desktop - but i note your app is set to build for iOS only. That also means that the specialFolderPath("documents") is not your Documents folder, but the sandboxed app-specific Documents for your mobile app. Could this be the reason it's not working for you?
so, to make your code more readable, i personally would change this:
Code: Select all
on preOpenCard
local tToDoList, tCarNotes, tNotename, tCarNote, tNoteTime, tCarBuild, tTry,tName,tToDolistDataArray,tDGLines,tSavedFile
local tSavedFile2, tLines
set the itemDelimiter to tab
--answer "preopening Receipt list card"
set the itemDelimiter to tab
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp" & "/Receipt.txt") into tSavedFile
--put url ("file:" & specialFolderPath("engine") & "/CarBuildApp" & "/Receipt.txt") into tSavedFile
--put url "file:" & specialFolderPath("documents") & "/CarBuildApp" & "/Receipt.txt" into tSavedFile
--answer tSavedFile
---open file (specialFolderPath("engine") & "/CarBuildApp" & "/Receipt.txt") for read
--read from file "Receipt.txt:" until EOF
--put it into tSavedFile2
answer tSavedFile
repeat with x = 1 to the number of lines of tSavedFile
put item 1 of line x of tSavedFile into item 1 of line x of tName
put item 2 of line x of tSavedFile into item 2 of line x of tName
put item 3 of line x of tSavedFile into item 3 of line x of tName
put item 4 of line x of tSavedFile into item 4 of line x of tName
put item 5 of line x of tSavedFile into item 5 of line x of tName
put item 6 of line x of tSavedFile into item 6 of line x of tName
put item 7 of line x of tSavedFile into item 7 of line x of tName
put item 9 of line x of tSavedFile into item 9 of line x of tName
put item 10 of line x of tSavedFile into item 10 of line x of tName
end repeat
--answer tName
filter tName without empty
get number of lines in tName
put it into tLines
repeat with x = 1 to tLines
put item 1 of line x of tName into tToDolistDataArray[X]["Create Date"]
put item 2 of line x of tName into tToDolistDataArray[X]["Date"]
put item 3 of line x of tName into tToDolistDataArray[X]["Store"]
put item 4 of line x of tName into tToDolistDataArray[X]["Category"]
put item 5 of line x of tName into tToDolistDataArray[X]["CDate2"]
put item 6 of line x of tName into tToDolistDataArray[X]["Cost"]
--put item 7 of line x of tName into tToDolistDataArray[X]["img"]
put item 9 of line x of tName into tToDolistDataArray[X]["Taxes Paid"]
put item 10 of line x of tName into tToDolistDataArray[X]["Image"]
end repeat
set the dgData of group "dgReceipt" of me to tToDolistDataArray
get the dgNumberOfLines of group "dgReceipt"
put it into tDGLines
end preOpenCard
Code: Select all
on preOpenCard
populateGridFromFile
end preOpenCard
command populateGridFromFile
local tToDolistDataArray, tSavedFile, x, tKeyNames
set the itemDelimiter to tab
put url ("File:" & specialFolderPath("documents") & "/CarBuildApp/Receipt.txt") into tSavedFile
put "Create Date,Date,Store,Category,CDate2,Cost,img,Taxes Paid,image" into tKeyNames
set the itemDelimiter to comma
repeat for each line tLine in tSavedFile
add 1 to x
repeat with y = 1 to the number of items of tKeyNames
put item y of tLine into tToDolistDataArray[x][item y of tKeyNames]
end repeat
end repeat
set the dgData of group "dgReceipt" of me to tToDolistDataArray
end populateGridFromFile
If you build for desktop this will almost certainly work as expected. Note that your 'receipts.txt' file starts with a line that contains a tab - i don't know if this is intentional, but it means the first line of the data grid won't have any text in it - if you want to change this then just add some code to remove the lines that don't 'have any text in them.
Also note that if you're using a data grid as a table and not a form, you don't necessarily need an array if your source data is tab-delimited text. If formatted correctly (eg empty fields are denoted by 2 consecutive tabs, fields in correct order and so on), you can assign the tab delimited text directly to the dgText property of the data grid and it will populate it.
With respect to the mobile build: How are you getting the text file into the mobile sandboxed Documents folder? I wonder if this is the problem you're having?