New to HyperCard and having a script error

Working on making the switch to SuperCard? Many here have done it... ask your questions here.

New to HyperCard and having a script error

Postby oz81dog » Wed Dec 19, 2012 12:39 pm

Hello,

I'm new to HyperCard and have been charged with migrating an existing project to SuperCard. The migration process went fine but when I go through the card I'm getting a script error on this routine that gets called all the time. Here's the code of the routine:

Code: Select all
on avgsa
if bg fld  16 is not empty then
put bg fld  16 & "," into holder
end if

if bg fld  17 is not empty then
put bg fld  17 & "," after holder
end if
if bg fld  18 is not empty then
put bg fld  18 & "," after holder
end if
if bg fld  19 is not empty then
put bg fld  19 & "," after holder
end if
if bg fld  20 is not empty then
put bg fld  20 & "," after holder
end if
if bg fld  21 is not empty then
put bg fld  21 & "," after holder
end if
if bg fld  22 is not empty then
put bg fld  22 & "," after holder
end if

put Average (holder) into myAvg               << The error comes up here
set the numberformat to "00.00"
put myAvg into bg fld id 33

end avgsa


I put a little comment in there, but it looks to me like the myAvg variable hasn't been declared? I know nothing of this language... :)

Does anyone have any ideas for me?
oz81dog
 
Posts: 4
Joined: Wed Dec 19, 2012 12:29 pm

Re: New to HyperCard and having a script error

Postby codegreen » Wed Dec 19, 2012 2:42 pm

Try changing your code as follows:

Code: Select all
on avgsa
  local myAvg, holder
  if isNumber(bg fld 16) then put bg fld 16 & "," after holder
  if isNumber(bg fld 17) then put bg fld 17 & "," after holder
  if isNumber(bg fld 18) then put bg fld 18 & "," after holder
  if isNumber(bg fld 19) then put bg fld 19 & "," after holder
  if isNumber(bg fld 20) then put bg fld 20 & "," after holder
  if isNumber(bg fld 21) then put bg fld 21 & "," after holder
  if isNumber(bg fld 22) then put bg fld 22 & "," after holder
  if holder is empty then put 0 into holder else delete last char of holder
  set the numberformat to "00.00"
  put Average(holder) into bg fld id 33
end avgsa

HTH,
-Mark
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: New to HyperCard and having a script error

Postby oz81dog » Wed Dec 19, 2012 4:29 pm

Thanks Mark, that worked like a charm. One more bug to squash and I think we're up and running.
oz81dog
 
Posts: 4
Joined: Wed Dec 19, 2012 12:29 pm

Re: New to HyperCard and having a script error

Postby LorenzT » Thu Dec 20, 2012 5:39 am

You could make this even a little bit shorter

Code: Select all
on avgsa
  local myAvg, holder
  repeat with i=16 to 22
  if isNumber(bg fld i) then put bg fld i into item i of holder
  end repeat
  if holder is empty then put 0 into holder
  set the numberformat to "00.00"
  put Average(holder) into bg fld id 33
end avgsa


Lorenz
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland


Return to Upgrading From HyperCard

Who is online

Users browsing this forum: No registered users and 1 guest