How do i connect datagrid information
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: How do i connect datagrid information
Here is the part that works:
ask "What is user pin?"
put it into theADPin
if it is empty then exit to top
dispatch "FindIndex" to group "playerData" on card 3 with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "userData" on card 3 into theDataA
#this puts the user name and such into the "activeuser" dg.
#when I log them out I determine their points
answer question "Would you like me to log player off machine 1?" with "No" or "Yes"
if it is "No" then exit to top
if it is "Yes" then
ask "What is the new score for machine 1?"
if it is empty then exit to top
put it into theNewScore
put the dgText of group "machineData" on card 5 into temp #old score
set the itemdel to tab
put item 6 of line 1 of temp into theOldScore
put (theNewScore + theOldScore) into varA
put (varA - theNewScore) into ntemp # I did this to avoid negative numbers
put the dgText of group "activeuser" into utemp
set the itemdel to tab
put item 8 of line 1 of utemp into varB
set the numberFormat to "#.00"
# varB is the right number, and ntemp is right, as I checked with the answer dialog, I made theADpin a local variable so it can be used in the second script. I think that with information from 3 different dg's it is confusing me. I just need to put the new score into the user dg and the new score into the machine dg but make sure it goes to the correct user and correct machine...sorry about the formatting I just pasted it in. It looks much cleaner in the app.
put (ntemp * varC) into varP
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "activeuser" into theDataB
put theADPin into DataB["pin"]
put varP into DataB["Points"]
#put "1" into theDataB["LineNo"]
#put 1 into theLineNo
dispatch "AddData" to group "userData" on card 3 with theDataB #, theLineNo
put the result into theIndex
end if
This was my attempt to put the user data back I haven't started the machine part. I think there might even be a better approach to all this but I am following the examples I have found. If you have a better solution I am all ears. I really want to learn the right way and use best practices.
Don
ask "What is user pin?"
put it into theADPin
if it is empty then exit to top
dispatch "FindIndex" to group "playerData" on card 3 with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "userData" on card 3 into theDataA
#this puts the user name and such into the "activeuser" dg.
#when I log them out I determine their points
answer question "Would you like me to log player off machine 1?" with "No" or "Yes"
if it is "No" then exit to top
if it is "Yes" then
ask "What is the new score for machine 1?"
if it is empty then exit to top
put it into theNewScore
put the dgText of group "machineData" on card 5 into temp #old score
set the itemdel to tab
put item 6 of line 1 of temp into theOldScore
put (theNewScore + theOldScore) into varA
put (varA - theNewScore) into ntemp # I did this to avoid negative numbers
put the dgText of group "activeuser" into utemp
set the itemdel to tab
put item 8 of line 1 of utemp into varB
set the numberFormat to "#.00"
# varB is the right number, and ntemp is right, as I checked with the answer dialog, I made theADpin a local variable so it can be used in the second script. I think that with information from 3 different dg's it is confusing me. I just need to put the new score into the user dg and the new score into the machine dg but make sure it goes to the correct user and correct machine...sorry about the formatting I just pasted it in. It looks much cleaner in the app.
put (ntemp * varC) into varP
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "activeuser" into theDataB
put theADPin into DataB["pin"]
put varP into DataB["Points"]
#put "1" into theDataB["LineNo"]
#put 1 into theLineNo
dispatch "AddData" to group "userData" on card 3 with theDataB #, theLineNo
put the result into theIndex
end if
This was my attempt to put the user data back I haven't started the machine part. I think there might even be a better approach to all this but I am following the examples I have found. If you have a better solution I am all ears. I really want to learn the right way and use best practices.
Don
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How do i connect datagrid information
This looks mostly right. Since you are updating data you want to set the dgDataOfIndex rather than calling AddData.Dr. Linux wrote:I just need to put the new score into the user dg and the new score into the machine dg but make sure it goes to the correct user and correct machine...sorry about the formatting I just pasted it in. It looks much cleaner in the app.
put (ntemp * varC) into varP
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "activeuser" into theDataB
put theADPin into DataB["pin"]
put varP into DataB["Points"]
#put "1" into theDataB["LineNo"]
#put 1 into theLineNo
dispatch "AddData" to group "userData" on card 3 with theDataB #, theLineNo
put the result into theIndex
end if
Code: Select all
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataB
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: How do i connect datagrid information
I still can't seem to get it to update the user dg. Is it possible that all my fooling around has broken my datagrid? The points still don't show up in the user dg.
Re: How do i connect datagrid information
I can add the data back into the user datagrid but it adds a duplicate row. Is there a way I can delete the row after i pull it out when using the "pin" once i get the index? I think if I delete it from the userdg after i pull it out and put it into theDataA, do my stuff then put the new result back into the user datagrid then it should work and line numbers and such shouldn't matter. I have the row in a temp variable so i wont lose the user data. Does this sound reasonable? In effect it just rotates the information in and out of the dg.
D
D
Re: How do i connect datagrid information
I still cannot delete a row after I pull it out of the dg. I am able to add the points and put the row back but it still just adds a new row. I thought the row would be hilited when acted on so that I could either send or dispatch to delete the row but none of my attempts have worked.
I'm sure there is a way to identify the row or pull out the line number so it can be deleted just not sure of the sytax. I know the datagrid isn't really made for this sort of thing but I can do so interesting stuff with them.
Trevor I think once I finish this project I'll send you a copy, just be sure and have an extra pair of clean pants cause you might need them after seeing the results! (hahaha!)
Don

Trevor I think once I finish this project I'll send you a copy, just be sure and have an extra pair of clean pants cause you might need them after seeing the results! (hahaha!)
Don
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How do i connect datagrid information
Don - can you post the new code you have? You don't need to delete the row or create a new one. Setting the dgDataOfIndex will update the row data (assuming you didn't delete the row). The other thing to keep in mind is that the index value is not necessarily the same as the row the index is displayed in. An index stays the same but a row can change based on how you sort the data, if you delete a row, etc.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: How do i connect datagrid information
Hi Doc,
1. Copy script in Livecode (will include formatting, hopefully
)
2. Paste here
3. Select that script HERE and click the "Code" button above
4. Voila, formatting preserved!
Best
Klaus
Do this:Dr. Linux wrote:...sorry about the formatting I just pasted it in. It looks much cleaner in the app.
1. Copy script in Livecode (will include formatting, hopefully

2. Paste here
3. Select that script HERE and click the "Code" button above
4. Voila, formatting preserved!

Best
Klaus
Re: How do i connect datagrid information
Here is what I have:
if it is "Logon" then
ask "What is the machine number?"
put it into theMachine
if it is empty then exit to top
ask "What is user pin?"
put it into theADPin
if it is empty then exit to top
dispatch "FindIndex" to group "userData" on card 3 with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "userData" on card 3 into theDataA
lock screen
set the icon of btn "mach1" to "34310"
unlock screen
put theADPin into theDataA["pin"]
put "1" into theDataA["machineno"]
put "1" into theDataA["lineno"]
put 1 into theLineNo
dispatch "AddData" to group "activeuser" with theDataA, theLineNo
put the result into theNewIndex
This works fine and populates the "activeuser" dg
This is the logout part that is giving me problems:
put (ntemp * varC) into thevarD
#answer thevarD
#dispatch "FindIndex" to group "userData" with "pin", theADPin
#put the result into theIndex
#if theIndex > 0 then
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataA
#put theADPin into theDataA["pin"]
put thevarD + varE into theDataA["points"]
#put "1" into theDataB["LineNo"]
#put "theLineT" into theLineNo
dispatch "AddData" to group "userData" on card 3 with theDataA #, theLineNo
put the result into theNewIndex
#end if
##Here is where I remove the line once the activeuser logs off.
put the dgIndexOfLine[1] of group "activeuser" into theUIndex
send "DeleteIndex theUIndex" to group "activeuser"
I don't know why it just adds a line and doesn't just update the original line...hmm?
Don
if it is "Logon" then
ask "What is the machine number?"
put it into theMachine
if it is empty then exit to top
ask "What is user pin?"
put it into theADPin
if it is empty then exit to top
dispatch "FindIndex" to group "userData" on card 3 with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put the dgDataOfIndex[theIndex] of group "userData" on card 3 into theDataA
lock screen
set the icon of btn "mach1" to "34310"
unlock screen
put theADPin into theDataA["pin"]
put "1" into theDataA["machineno"]
put "1" into theDataA["lineno"]
put 1 into theLineNo
dispatch "AddData" to group "activeuser" with theDataA, theLineNo
put the result into theNewIndex
This works fine and populates the "activeuser" dg
This is the logout part that is giving me problems:
put (ntemp * varC) into thevarD
#answer thevarD
#dispatch "FindIndex" to group "userData" with "pin", theADPin
#put the result into theIndex
#if theIndex > 0 then
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataA
#put theADPin into theDataA["pin"]
put thevarD + varE into theDataA["points"]
#put "1" into theDataB["LineNo"]
#put "theLineT" into theLineNo
dispatch "AddData" to group "userData" on card 3 with theDataA #, theLineNo
put the result into theNewIndex
#end if
##Here is where I remove the line once the activeuser logs off.
put the dgIndexOfLine[1] of group "activeuser" into theUIndex
send "DeleteIndex theUIndex" to group "activeuser"
I don't know why it just adds a line and doesn't just update the original line...hmm?
Don
Last edited by Dr. Linux on Sat Aug 31, 2013 9:44 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How do i connect datagrid information
You need to find the index in the "activeuser" data grid that is associated with the "pin". I don't see any code that does this. Here is one way to modify what you have:
Don't do the above. "AddData" will always add a new line. If the data already exists in the data grid then you want to set the dgDataOfIndex only.
Code: Select all
put (ntemp * varC) into thevarD
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put thevarD + varE into theDataA["points"]
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataA
end if
Code: Select all
dispatch "AddData" to group "userData" on card 3 with theDataA #, theLineNo
put the result into theNewIndex
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: How do i connect datagrid information
Well, I spoke too soon. I checked the math and the points are not adding up. I can put the data into the activeuser dg but I can't put them back into the user dg after new points are added. If I put the data into theDataA, how do I then put theDataA back into the user dg. I pull the user info out for the login which is then displayed in the activeuser dg, then as I log them out I add the new points then I add the new Data back into the user dg. It's not adding a line anymore but it's not updating the data either. I'm not sure how to set the data to the user dg if it is in theDataA without using dispatch or send.
Last edited by Dr. Linux on Tue Sep 03, 2013 4:32 pm, edited 1 time in total.
Re: How do i connect datagrid information
Oh, and thank you Klaus, I don't think I am getting everything when I copy. I use a laptop and the mouse pad which is a pain,(like playing a tiny three finger piano
) but I will take your advice and use the code tool. I admit I didn't realize how to use the buttons above the reply text field until you pointed it out. Very Cool!!!
D

D
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How do i connect datagrid information
You assign an array (in your case, theDataA) back to an index usingDr. Linux wrote:Well, I spoke too soon. I checked the math and the points are not adding up. I can put the data into the activeuser dg but I can't put them back into the user dg after new points are added. If I put the data into theDataA, how do I then put theDataA back into the user dg.
Code: Select all
set the dgDataOfIndex[theIndex] of group "userdg"] to theDataA
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: How do i connect datagrid information
I think I understand. Is this how I would do it?
put (ntemp * varC) into thevarD
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put thevarD + varE into theDataA["points"]
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataA
set the dgDataOfIndex[theIndex] of group "userData"] on card 3 to theDataA
#I'm getting an error
button "mach1": compilation error at line 77 (set: missing 'to'), char 50
Don
put (ntemp * varC) into thevarD
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put thevarD + varE into theDataA["points"]
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataA
set the dgDataOfIndex[theIndex] of group "userData"] on card 3 to theDataA
#I'm getting an error
button "mach1": compilation error at line 77 (set: missing 'to'), char 50
Don
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How do i connect datagrid information
I think you need to find the user in the "userdata" data grid as well. I don't know that the index will be the same for the "activeuser" and the "userdata".
BTW - I think your error is caused by the extra ] after "userData"] and saying "on card 3" rather than "of card 3".
Code: Select all
put (ntemp * varC) into thevarD
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put thevarD + varE into theDataA["points"]
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataA
end if
Code: Select all
dispatch "FindIndex" to group "userData" of card 3 with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
set the dgDataOfIndex[theIndex] of group "userData" of card 3 to theDataA
end if
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: How do i connect datagrid information
The error is gone but the user dg still isn't updating. Here is the rest of the script that I have been using for mach1. Does it matter that I delete the row after the user logs off?
put (ntemp * varC) into thevarD
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put thevarD + varE into theDataA["points"]
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataB
end if
dispatch "FindIndex" to group "userData" of card 3 with "pin", theADPin
put the result into theIndex
if theNIndex > 0 then
set the dgDataOfIndex[theIndex] of group "userData" of card 3 to theDataB
end if
put the dgIndexOfLine[1] of group "activeuser" into theIndex
send "DeleteIndex theIndex" to group "activeuser"
lock screen
set the icon of btn "mach1" to "34309"
unlock screen
put (ntemp * varC) into thevarD
dispatch "FindIndex" to group "activeuser" with "pin", theADPin
put the result into theIndex
if theIndex > 0 then
put thevarD + varE into theDataA["points"]
set the dgDataOfIndex[theIndex] of group "activeuser" to theDataB
end if
dispatch "FindIndex" to group "userData" of card 3 with "pin", theADPin
put the result into theIndex
if theNIndex > 0 then
set the dgDataOfIndex[theIndex] of group "userData" of card 3 to theDataB
end if
put the dgIndexOfLine[1] of group "activeuser" into theIndex
send "DeleteIndex theIndex" to group "activeuser"
lock screen
set the icon of btn "mach1" to "34309"
unlock screen