Page 1 of 1

format datagrid values with function

Posted: Tue May 05, 2015 10:50 pm
by jalz
Hi Guys,

I have the following sql statement below which works OK. However I've written a function called returnCurrency which adds currency symbol, decimal, commas for every thousand, two digits to indicate pence etc to a whole number and I want to wrap this function around my fields item_price and line_price. As I'm populating a datagrid using "set the dgText", I'm not quite sure how to achieve this - can someone give me some pointers. My initial thoughts were to convert the item values before I use the set dgText (as you can see, ive commented them out as they were not working), but that didn't work as it populated the column with data formatted incorrectly, perhaps it was the comma that threw out the formatting...

Code: Select all

put "SELECT material, item_price, qty, line_price, lineID FROM project_material WHERE projectID =" && "'" & tProjectID & "'" & "ORDER BY lineID" into tTheSQLQuery
      
      put revDataFromQuery(tab, cr, gConnID, tTheSQLQuery) into tTheData
      if tTheData begins with "revdberr," then
         delete item 1 of tTheData
      else
         --put returnCurrency(item 2 of tTheData) into item 2 of tTheData
         --put returnCurrency(item 4 of tTheData) into item 4 of tTheData
         
         set the dgText[true] of me to "material" & tab & "item_price" & tab & "qty" & tab & "line_price" & tab & "lineID" & cr & tTheData
      end if

Re: format datagrid values with function

Posted: Tue May 05, 2015 11:23 pm
by dunbarx
Hi.

If you are working the data in the clear, before reloading the DG, then simply apply your function to each item (delimited as you have them) as appropriate, no? This is what I do, because I am still uncomfortable working inside the DG itself, mucking around with the internal "cell" values using native DG gadgetry. I do it all outside in a normal variable, and unload and reload ad nauseam.

Craig Newman

Re: format datagrid values with function

Posted: Wed May 06, 2015 7:25 pm
by sritcp
jalz wrote:.....My initial thoughts were to convert the item values before I use the set dgText (as you can see, ive commented them out as they were not working), but that didn't work as it populated the column with data formatted incorrectly, perhaps it was the comma that threw out the formatting...
Did you
set the itemDel to tab
before doing the conversion?

Regards,
Sri

Re: format datagrid values with function

Posted: Wed May 06, 2015 7:54 pm
by dunbarx
Hi.

Sri wrote:
Did you set the itemDel to tab before doing the conversion?
Is that possibly your issue?

I had written:
...apply your function to each item (delimited as you have them)...
Do you know what we mean?

Craig

Re: format datagrid values with function

Posted: Wed May 06, 2015 10:25 pm
by jalz
Thanks to both of you, yes it was the item delimiter that I forgot to set….

Now that its set, the first line of data is formatting correctly, but subsequent lines are not. So I'm trying to use an repeat each line loop, but its not returning my results. Am I putting the data back correctly in the line the way I have written it?

Code: Select all


      set itemdel to TAB
      
      if tTheData begins with "revdberr," then
         delete item 1 of tTheData
      else
         repeat for each line i in tTheData
            put returnCurrency(item 2 of i, "true") into item 2 of i
            put returnCurrency(item 4 of i, "true") into item 4 of i
         end repeat
        
         set the dgText[true] of me to "material" & tab & "item_price" & tab & "qty" & tab & "line_price" & tab & "lineID" & cr & tTheData

Re: format datagrid values with function

Posted: Wed May 06, 2015 11:44 pm
by dunbarx
Hi.

You are changing the item values, line by line, of the "local" contents of tTheData WITHIN the loop, but never actually doing anything with those changes. Step through the repeat loop and watch what happens. The code executes just fine, but nothing comes of it. Each new line is modified in turn, and then, nothing.

There are about a million ways out of this. I bet you do not need one from me.

Craig