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
-
lemodizon
- Posts: 175
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Fri Oct 13, 2023 2:38 pm
Hi everyone,
good day
I bought a widget polygrid from livecode.
This is my first time to use this widget can some one teach me how to get the total sum in one column.
sorry for my code if they are long codes for you i'm still trying and learning to make it short.
Code: Select all
on checkData
if fld "fldQtty" is empty or hilitedbutton of grp "grpType" is 0 or hilitedbutton of grp "grpLoc" is 0 then
beep
Answer error "May nakalimutan ka ilagay pa." titled "Error: May nakalimutan ilagay"
else
put fld "fldQtty" into tQtty
if the hilite of btn "Round" then
put "Round" into tType
end if
if the hilite of btn "Slim" then
put "Slim" into tType
end if
if the hilite of btn "Clark" then
put "Clark" into tLoc
end if
if the hilite of btn "Sapangbato" then
put "Sapangbato" into tLoc
end if
if the hilite of btn "WalkIn" then
put "Walk-IN" into tLoc
end if
put tQtty &TAB& tType &TAB& tLoc &TAB& short Time &TAB& short Date into tNewInputData
put the pgText of widget "PgridGallon" of stack "StackGallons" into tOldData
if tOldData is empty then
put tNewInputData into tOldData
else
put cr & tNewInputData after tOldData
end if
set the pgText of widget "PgridGallon" of stack "StackGallons" to tOldData
end if
repeat for each key tkey in tOldData // i just got this code from the dictionary
put tOldData [tkey]["cQtty"] into tQtty
// i'm stuck here I don't what's next code
end checkData
this past days i tried using field and repeat to get the sum thanks for those who share their knowledge in that topic.
-
Attachments
-
Thank you & God Bless Everyone
Regards,
lemodizon
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Fri Oct 13, 2023 3:28 pm
Maybe this is what you are missing:
Code: Select all
...
repeat for each key tkey in tOldData // i just got this code from the dictionary
put tOldData [tkey]["cQtty"] into tQtty
add tQtty to tTotalSum
end repeat
...
I'm not sure WHERE exactly you want to display the tTotalSum in the end?
-
cpuandnet
- Posts: 32
- Joined: Thu Jan 17, 2019 6:43 am
Post
by cpuandnet » Fri Oct 13, 2023 4:25 pm
Hi Lemodizon,
Looking at your code, keep in mind that you are using pgText not pgData. With pgText, think lines and items not arrays, elements and keys like you would with pgData. So, in lieu of that I would use something like this, assuming that the quantity column is the first column and you have no invisible columns before it:
Code: Select all
set itemDelimiter to tab
repeat with tLineNo = 1 to the number of lines of tOldData
add item 1 of line tLineNo of tOldData to tSumTotal
end repeat
I hope this helps.
Tim
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Fri Oct 13, 2023 4:42 pm
Ouch, totally overlooked this, of course you are right!
-
lemodizon
- Posts: 175
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Sat Oct 14, 2023 12:16 pm
Hi Tim & klaus,
thank you for helping me out. I appreciate your help guys.
Which one is better polygrid or datagrid?
Thank you & God Bless Everyone
Regards,
lemodizon
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Sat Oct 14, 2023 1:02 pm
It depends...
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Sat Oct 14, 2023 2:15 pm
I would say a PolyGrid is easier to create and manage, but a datagrid is a bit more powerful but has also a very steep leraning curve!
E.g. the user can modify text by doubleclicking a cell in a Datagrid (if the programmer allows), that is not possible with a PolyGrid.
-
lemodizon
- Posts: 175
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Sat Oct 14, 2023 3:25 pm
Hi Klaus,
Thanks. how do you sort in polygrid? i can't find in the property inspector. While in data grid property inspector it is available.
i tried this code nothing happens in my polygrid.
Code: Select all
sort lines of tOldData descending numeric by item 1 of each
Thank you & God Bless Everyone
Regards,
lemodizon
-
cpuandnet
- Posts: 32
- Joined: Thu Jan 17, 2019 6:43 am
Post
by cpuandnet » Sat Oct 14, 2023 3:33 pm
As Klaus indicated, the polygrid is easier. Start with the polygrid and see if that fills your requirements. If not, then you can move to the datagrid. The datagrid is very powerful but can also be a bit fussy or slow at times so you really need to experiment in your learning process of the datagrid.
On you sorting, did you set the pgText of the polygrid with tOldData?
Tim
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Sat Oct 14, 2023 3:46 pm
Hi lemodizon
lemodizon wrote: ↑Sat Oct 14, 2023 3:25 pm
...
i tried this code nothing happens in my polygrid.
Code: Select all
sort lines of tOldData descending numeric by item 1 of each
well, that will sort the lines of the VARIABLE tOldData!
As Tim stated, you then also need to:
Code: Select all
set the pgText of widget "your polygrid" to tOldData
again!
Best
Klaus
-
lemodizon
- Posts: 175
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Mon Oct 16, 2023 12:00 pm
Hi Klaus,
Thanks again I really appreciate your help.
Thank you & God Bless Everyone
Regards,
lemodizon
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Mon Oct 16, 2023 12:07 pm
It was Tim who gave the final clue!
-
lemodizon
- Posts: 175
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Mon Oct 16, 2023 12:58 pm
Thanks Tim and Klaus
Thank you & God Bless Everyone
Regards,
lemodizon