[comp.sys.mac.hypercard] more 2.0 probs - number precision, file operations

rgoldstone@OAVAX.CSUCHICO.EDU (Robin Goldstone) (11/30/90)

Hi- I posted earlier about several problems I was having with a stack 
I converted to HC 2.0 format. The stack is a front end for an Oracle 
database.  I have discovered even *more* problems with the stack.  
I am getting extremely frustrated that so many thing are breaking!  
Here are my two current problems:

1) I have a card that represents an "invoice".  The user fills in some 
stuff and my script calculates the total invoice amount (i.e. adds up item 
prices * quantities and calculates sales tax and total invoice amount). 
All of a sudden the user noticed that sales tax was not being computed 
correctly.  Our sales tax is 6.025%.  In my stack, I have:
  put .0625 into taxRate
When I debug the script, the variable watcher shows that taxRate 
contains .06.  Has something changed regarding default number precision?  
Where are my other two significant digits?!  Do I have to somehow tell HC 
what precision I want?

2) another card  is a "report writer". It extracts records from the Oracle DB 
and writes them to a text file.  The structure is: open file, write records, 
close file.  Pretty standard stuff.  Well, now when this script gets to the 
"close file" statement, I get a dialog box stating "No open file named "xxx".
In other words, it is telling me the file is somehow already closed!  This is  
strange.  I have debugged the script but can't figure out what the problem is. 
The file is successfully opened and all the records are written.  It is just 
somehow getting closed before I can close it!  Here is a chunk of the script:

  put "hard:ls:CUSTOMER REPORT" into fileName
  open file fileName
  execsql "get next row"    <-- oracle command to extract a record 
  repeat forever
    repeat with i = 5 to 14
        put card field i  & tab after tempRec
      end if
    end repeat
    put return after tempRec
    write tempRec to file fileName
    execsql "get next row"
    if the result <> 0 then   <-- means no more records found
      close file fileName    <-- this is where it bombs out!
      exit repeat
    end if
    put empty into tempRec
  end repeat

Sorry this is so long, but I am desparate to solve these problems... Please
keep in mind that these things all worked correctly at HC 1.2.5.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                                           |
|  Robin Goldstone, Systems Software Specialist                             |
|  California State University, Chico   Computing Services                  |
|  rgoldstone@oavax.csuchico.edu                                            |
|                                                                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

clarson@ux.acs.umn.edu (Chaz Larson) (11/30/90)

In article <009406E0.A248D460@OAVAX.CSUCHICO.EDU> rgoldstone@OAVAX.CSUCHICO.EDU (Robin Goldstone) writes:
|1) I have a card that represents an "invoice".  The user fills in some 
|stuff and my script calculates the total invoice amount (i.e. adds up item 
|prices * quantities and calculates sales tax and total invoice amount). 
|All of a sudden the user noticed that sales tax was not being computed 
|correctly.  Our sales tax is 6.025%.  In my stack, I have:
|  put .0625 into taxRate
|When I debug the script, the variable watcher shows that taxRate 
|contains .06.  Has something changed regarding default number precision?  
|Where are my other two significant digits?!  Do I have to somehow tell HC 
|what precision I want?

Do you have a "set numberformat to 0.00" statement in there somewhere?

chaz

-- 
Someone please release me from this trance.
clarson@ux.acs.umn.edu                                       AOL:Crowbone

rgoldstone@OAVAX.CSUCHICO.EDU (Robin Goldstone) (12/01/90)

In article <2786@ux.acs.umn.edu>, clarson@ux.acs.umn.edu (Chaz Larson) writes:
>In article <009406E0.A248D460@OAVAX.CSUCHICO.EDU> I write:
>|1) I have a card that represents an "invoice".  The user fills in some 
>|stuff and my script calculates the total invoice amount (i.e. adds up item 
>|prices * quantities and calculates sales tax and total invoice amount). 
>|All of a sudden the user noticed that sales tax was not being computed 
>|correctly.  Our sales tax is 6.025%.  In my stack, I have:
>|  put .0625 into taxRate
>|When I debug the script, the variable watcher shows that taxRate 
>|contains .06.  Has something changed regarding default number precision?  
>|Where are my other two significant digits?!  Do I have to somehow tell HC 
>|what precision I want?
>
>Do you have a "set numberformat to 0.00" statement in there somewhere?
>
Yes, as a matter of fact I do.  I need that so that the amounts displayed
on the invoice have two significant digits.  I anaylzed this some more last
night.  When I first wrote the stack, I was under the assumption that 
numberFormat just affected the precision at which numbers were *displayed*
not the precision at which they were *calculated*.  And my assumption was
validated by the fact that this worked as I had thought. With HC 1.2.5 I had 
numberFormat set to 0.00, I put .0625 in taxRate and everything was calculated 
correctly. I swear it is true!!  I went back and double-checked some invoices
that were done under HC 1.2.5.  Sales tax was properly calculated at 6.25%.
Now it is only being calculated at 6%.  Nothing in my script has changed.
All I did was install HC 2.0 and do a "convert stack".

Looking at the HyperTalk 2.0 Reference Stack, it does seem to imply that
numberFormat affects computation of variables, not just how they are displayed.
So I feel that I misinterpreted it before.  Yet it worked... So maybe it
was HC 1.2.5 that was doing it wrong and HC 2.0 has actually fixed this.
Any comments from Apple/Claris?!

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                                           |
|  Robin Goldstone, Systems Software Specialist                             |
|  California State University, Chico   Computing Services                  |
|  rgoldstone@oavax.csuchico.edu                                            |
|                                                                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) (12/05/90)

Remember that HyperCard doesn't do any formatting of numbers for display
as such: the values of all variables are strings to begin with. In HC 2.0,
the NumberFormat property is used every time a number is converted to a
string, and at no other time. Some example situations (A and B are
any valid containers):

	Put A into B -- A and B are always strings, NumberFormat has no effect
	Put "0.625" into B -- explicit string literal, again no formatting
	Add A to B -- strings get converted to numbers, arithmetic is done,
		-- and result is converted back to a string according to
		-- current NumberFormat
	Put 0.625 into B -- number gets converted into string according to
		    	-- current NumberFormat

I guess the HyperCard people must have considered the old behaviour
a bug, or at least an inconsistency.

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00