[help] What's wrong with this code ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

[help] What's wrong with this code ?

Post by shawnblc » Thu Jun 18, 2015 10:21 pm

I am able to write data to the datagrid, but when I submit a second time my first entry is replaced. When I change my code to this nothing is added though:

Code: Select all

 put tDate into theRowData
   put tFacility into theRowData
   put tCategory into theRowData
   put fld "lblLink" into theRowData
   
   put the dgNumberOfLines of grp "DataGridFiles1" of stack "Filing Cabinet" + 1 into theLineNo
   dispatch "AddLine" to grp "DataGridFiles1" of stack "Filing Cabinet" with  theRowData, theLineNo
On my main stack I'm selecting my file and date, on my substack I'm adding the information. "Filing Cabinet" is my substack.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: [help] What's wrong with this code ?

Post by dunbarx » Thu Jun 18, 2015 10:30 pm

Hi.

You rewrite the contents of the variable "theRowData" three times. Is this intended?

AddLine requires a tab delimited string. Is there data in such a string when you dispatch?

Craig Newman

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: [help] What's wrong with this code ?

Post by shawnblc » Thu Jun 18, 2015 10:51 pm

dunbarx wrote:Hi.

You rewrite the contents of the variable "theRowData" three times. Is this intended?

AddLine requires a tab delimited string. Is there data in such a string when you dispatch?

Craig Newman

Let me show you what I'm trying. See image. No, I don't have a tab delimited string. I was trying to incorporate a few examples I've found. If you look at the image. The image on the left is my "Main Menu" stack. I select the file and successfully upload it to the server. Once the upload is completed I can use dispatch to populate the datagrid in the substack (previous code), but was always overwritten. So the above code I was attempting to create a new line for each document.

When I use this code I can add 1 single line each new entry overwrites the previous (not what I want).

Code: Select all

put 1 into theLineNo
   put tDate into theDataA[ 1 ][ "date" ]
   put tFacility into theDataA[ 1 ][ "facility" ]
   put tCategory into theDataA[ 1 ][ "category" ]
   put fld "lblLink" into theDataA[ 1 ][ "documentLink" ]

   

   set the dgData of group "DataGridFiles1" of stack "Filing Cabinet" to theDataA
   dispatch "AddLine" to group "DataGridFiles1" of stack "Filing Cabinet" with theDataA, theLineNo

   put the result into theNewIndex 
   
   
Attachments
attempting_this.png

hilton
Posts: 35
Joined: Sat Dec 13, 2014 11:16 am

Re: [help] What's wrong with this code ?

Post by hilton » Fri Jun 19, 2015 1:12 am

put tDate into theDataA[ 1 ][ "date" ]
If I understand the code, the index needs to change for each line else it will overwrite. You need to have

Code: Select all

put tDate into theDataA[ 1 ][ "date" ]
put tDate into theDataA[ 2 ][ "date" ]
put tDate into theDataA[ 3 ][ "date" ]
etc....

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: [help] What's wrong with this code ?

Post by shawnblc » Fri Jun 19, 2015 1:16 am

hilton wrote:
put tDate into theDataA[ 1 ][ "date" ]
If I understand the code, the index needs to change for each line else it will overwrite. You need to have

Code: Select all

put tDate into theDataA[ 1 ][ "date" ]
put tDate into theDataA[ 2 ][ "date" ]
put tDate into theDataA[ 3 ][ "date" ]
etc....
The problem with that is I don't know how many docs there will be, there could be several hundred / thousand. The user submits the documents, which are immediately uploaded to the server.

This is what I had previously:

Code: Select all

   put 1 into theLineNo
   put tDate into theDataA[ 1 ][ "date" ]
   put tFacility into theDataA[ 1 ][ "facility" ]
   put tCategory into theDataA[ 1 ][ "category" ]
   put fld "lblLink" into theDataA[ 1 ][ "documentLink" ]

D4vidrim
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 61
Joined: Fri May 31, 2013 9:32 am

Re: [help] What's wrong with this code ?

Post by D4vidrim » Fri Jun 19, 2015 5:51 am

shawnblc wrote: The problem with that is I don't know how many docs there will be, there could be several hundred / thousand. The user submits the documents, which are immediately uploaded to the server.
Why don't you count the number of record on that data grid first, then you add 1 to that number then you can insert the new record. :)

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: [help] What's wrong with this code ?

Post by shawnblc » Fri Jun 19, 2015 8:00 am

D4vidrim wrote:
shawnblc wrote: The problem with that is I don't know how many docs there will be, there could be several hundred / thousand. The user submits the documents, which are immediately uploaded to the server.
Why don't you count the number of record on that data grid first, then you add 1 to that number then you can insert the new record. :)
Let me see if I can figure that out. I'll update in a few minutes. Hmmmmm.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: [help] What's wrong with this code ?

Post by SparkOut » Fri Jun 19, 2015 8:04 am

You've been trying to AddLine with a (broken) array. In your very first post you might have succeeded if you had a properly constructed array of data, and then instead of dispatching "AddLine", dispatching "AddData" would probably have worked.
You then went on to make an array, which you then used to populate the whole datagrid, which worked, but the AddLine part failed. That's why it looked like you were overwriting with the new line - it wasn't, but you had already recreated the entire datagrid contents with that single line of data.
Then you say you don't know how many rows there are in the datagrid to be able to insert a correct new line number, but you already got that in the first post.
When you add data with an array, the array index should not match the line number, when you set the whole datagrid contents using an array, each array index will be a new record of data. You need to pass the new line number but not by the array index.

Code: Select all

   put tDate into theDataA[1]["date"]
   put tFacility into theDataA[1]["facility"]
   put tCategory into theDataA[1]["category"]
   put fld "lblLink" into theDataA[1]["documentLink"]
   
   put the dgNumberOfLines of grp "DataGridFiles1" of stack "Filing Cabinet" + 1 into theLineNo
   dispatch "AddData" to grp "DataGridFiles1" of stack "Filing Cabinet" with theDataA, theLineNo

   put the result into theNewIndex
You could alternatively do this with AddLine but that would need a tab delimited string, not an array. But in no case would you need to overwrite the dgData with an entirely new content.

Post Reply