Page 1 of 1

'Put' statement not working

Posted: Tue Apr 16, 2013 5:59 pm
by OzSanta
Newby here.

I'm trying to create an accounting stack. I've a main stack that keeps Quotes, invoices, overdues, and paid, and am now trying to create a substack that will show accounting figures. My problem is that the put statements don't work as I've written them.

Code: Select all

on doCalculate
   local theTotal,temp
   put field "Start Date" into theStartDate
   convert theStartDate  from long system date to seconds
   put field "End Date" into theEndDate
   convert theEndDate  from long system date to seconds
   lock screen
   go invisible to  stack "John's Quotes"
   put 0 into QuoteTotal
   put 0 into InvoiceTotel
   put 0 into OverdueTotal
   put 0 into PaidTotal
   put 0 into GSTTotal
   put 0 into GrandTotal
   repeat with x= 1 to number of last card 
      go to card x  
      put field "Date Field" into tempDate
      convert tempDate from long system date to seconds
      if tempdate  ≥ theStartDate and tempDate ≤ theEndDate then
         put thetext(field "Total" ) into theTotal --// why won't these work?
         put thetext(field "GST") into theGST
         put thetext(field "Grand Total") into theGrandTotal
         if button "Overdue" is visible then put  OverdueTotal +theGrandTotal into OverdueTotal
         if button "Paid" is visible then put  PaidTotal +theGrandTotal into PaidTotal
         if button "Paid" is visible then put   GSTTotal +theGST  into GSTTotal
         if button "Paid" is visible then put   GrandTotal + theGrandTotal into GrandTitle
      end if
   end repeat
   go to me
   show me
   formatField (QuotedField, QuoteTotal)
   unlock screen
end doCalculate

on  TheText mySelfField
   repeat while " " is in MySelfField  
      delete   char offset (" ",MySelfField) of MySelfField  
   end repeat
   repeat while "$" is in MySelfField 
      delete   char offset ("$" ,MySelfField ) of MySelfField  
   end repeat
   repeat while "," is in MySelfField  
      delete   char offset (",",MySelfField ) of MySelfField  
   end repeat
   answer myselffield
   return  (MySelfField )
end  TheText

Re: 'Put' statement not working

Posted: Tue Apr 16, 2013 6:31 pm
by bn
Hi ozsanta,

welcome to the forum.

I think it does not work because your handler "TheText" is defined as a command and not a function but you call it as a function

everything will probably work if you prepend "TheText" with "function" instead of "on" like

Code: Select all

function  TheText mySelfField
The difference in this case is that your current version returns "MySelfField" in the "result" as commands do when you tell them to send something back (return MySelfField) (they normally don't return anything that since that is what functions are for).
A function in contrast returns a value in "it" or in the format you used

Code: Select all

put thetext(field "GST") into theGST
Kind regards
Bernd

Re: 'Put' statement not working

Posted: Tue Apr 16, 2013 9:17 pm
by bn
Hi ozsanta,

while you are at it: this is a slightly easier version of your function:

Code: Select all

function  TheText mySelfField
   replace space with empty in mySelfField
   replace "$" with empty in mySelfField
   replace comma with empty in mySelfField
   
   --   repeat while " " is in MySelfField 
   --         delete   char offset (" ",MySelfField) of MySelfField 
   --   end repeat
   --   repeat while "$" is in MySelfField
   --         delete   char offset ("$" ,MySelfField ) of MySelfField 
   --   end repeat
   --   repeat while "," is in MySelfField 
   --         delete   char offset (",",MySelfField ) of MySelfField 
   --   end repeat
   ----   answer myselffield
   
      return MySelfField
end  TheText
Kind regards
Bernd

Re: 'Put' statement not working

Posted: Thu Apr 18, 2013 2:57 am
by OzSanta
G'day, and thanks Bernd

Regards

OzSanta