Extracting the value of the 'next' element in an array

Another option is to paste the code into the Edit panel, select it and click the Preformatted text icon or enter command-shift-C to preserve the formatting and keep the original quotes.

Thanks for all your suggestions. The problem arose because I had been writing the code in my word processor and then copying it to the procedure panel in PanX. The word processor put curly quotes on things and I failed to note the difference in PanX. Once I ‘straightened’ the quotes, all was well.
My bigger question now is that the code I put into the procedure panel caused PanX to crash. Any help you can give on remedying that, will be greatly appreciated.
Thanks again.

The problem is that your cited code had the curly quotes again. So we are not able to know if that is really the code you are using in Panorama.

Kurt,
Thanks for pointing out that I had missed some of the curly quotes. I want through and straightened all of them, but the procedure still caused PanX to crash.

Without knowing your databases I can only check if the code compiles correctly. This is the code with corrected quotes. The code check says it is OK.

local lvnumber
rememberwindow
opendatabase "Donations"
let gvdonor = listchoices(«ContactID»,", ")
gvdonor=arrayrange(gvdonor, 5, 9, ", ")
originalwindow

looparray gvdonor, ", ", lvnumber
lvnumber=val(lvnumber)
find «ContactID»=lvnumber
if info("found")
«lastdate»=lookuplast("Donations", «ContactID», lvnumber, «Date», "")
«totalsum»=aggregate("Amount", "sum","«ContactID»=lvnumber", "Donations", true())
endif
endloop

I tried things again and PanX did NOT crash, but, the following error message appeared in the procedure panel:
aggregate(function: database “(null)” is not open.

I was able to duplicate that the aggregate( function does not properly report the error when the specified database is not open. I have opened a bug report for this.

The more immediate question is why does it think the Donations database is not open. Clearly you have opened it earlier in the code, and the lookuplast( function also works. My guess is that there is an invisible character in the text "Donations".

I’m concerned that in the process of copying the text from a word processor, you may also have copied invisible characters from the word processor that are causing you all sorts of problems. I’m sorry you won’t like my advice, but my recommendation would be to completely erase all this code and then manually type it in again in Panorama’s code editor.

Jim,
Thank you for taking the time to look into this. I think you are absolutely right. I need to erase what I have and re-do it from scratch in the procedure panel completely within PanX. I had no idea that copying things would cause all these problems. Live and learn. Thanks again. I"ll let you know tomorrow how it worked.

You wouldn’t have a problem copying procedure code you had written using a text editor, e.g. TextEdit or fully fledged programming editors such as TextMate or BBEdit. However, as Jim says, word processors or DTP programs are another matter. They are likely to copy rich text to the clipboard which might contain extra characters you can’t see, as well as the more obvious appearance attributes (italic, bold, alignment, text size, font change, etc.) which Panorama’s editor will safely ignore.

Actually if you use TextEdit you have to be careful to use plain text mode, as TextEdit does support rich text. I would stick to either using Panorama’s editor or a pure programming editor like BBEdit or TextMate.

Good point.

OK. I deleted the procedure which had the potentially faulty text completely. I then made a new procedure and typed the code below directly into the PanX procedure panel. But it still gives me the error message: “aggregate( function: database “(null)” is not open.”
Here’s the code:

local lvnumber
rememberwindow
opendatabase "Donations"
let gvdonor = listchoices(«ContactID», ", ")
gvdonor=arrayrange(gvdonor, 5, 9, ", ")
originalwindow

looparray gvdonor, ", ", lvnumber
    lvnumber=val(lvnumber)
    find «ContactID» = lvnumber
    if info("found")
        «lastdate» = lookuplast("Donations", «ContactID», lvnumber, «Date»,"")
        «totalsum» = aggregate("Amount", "sum", "«ContactID»=lvnumber", true())
    endif
endloop

Your code is still using curly quotes. I would suggest that you take a good look at your system before posting the same error over and over and over. Check your system as your current settings may be working against you. ie. This system setting may be in use.

You aggregate function is missing a parameter. You’ve specified the database as true(), a Boolean value. You need to put the database name in front of that.

I did change my system preferences to insure that the quotes were straight and not curly. I then retyped the code and got the same result – error message: “aggregate( function: database “(null)” is not open.”

Yes, but what code did you retype? As Jim has pointed out, in the procedure that you quoted this morning there was an error in your use of the aggregate( formula. It requires between one and five parameters: formula (required), aggregation, queryformula, database and includeallrecords (all optional). If there are fewer than five, Panorama will assume you have supplied those you have given in the order in which they are required, therefore the fourth (for instance) will be assumed to be database. Therefore if you want to specify the fifth, includeallrecords, you must specify the preceding four too. But, as in most (all?) Panorama functions which refer to a database, you can use the empty string ("") to refer to the current database.

If that was your intention, the antepenultimate line of the code you quoted should be:

    «totalsum» = aggregate("Amount", "sum", "«ContactID»=lvnumber", "", true())

Peter,
Thank you very much. I had not noticed that I had not designated the database I wanted searched for the aggregate( function. When I designated it (“Donations”), it caused PanX to crash. I checked it a couple of times and it crashed each time I tried to run the procedure. This is really odd. Anyone have any ideas of what I’m doing wrong or not doing?

I duplicated your setup as best as I could, and I could not get a crash. I even tried things like trying to sum a text field instead of a numeric field, and or using non-existant fields. No crash. Perhaps your Donations database is corrupted?

I am assuming totalsum is a numeric field?

Let’s try to make this simpler. Please try this simple program and see if it works.

// substitute a real id number instead of 100
let lvnumber=100
message aggregate("Amount", "sum", "«ContactID»=lvnumber", "Donations", true())

I don’t see how it could cause a crash, but I don’t understand this line in your code:

gvdonor=arrayrange(gvdonor, 5, 9, ", ")

Why are you using only the 5th thru 9th choices? That seems very arbitrary and fragile. There’s no guarantee what order the choices will be listed in. But it certainly shouldn’t cause a crash.

Jim,
Thank you once again for taking the time to try to help me get this procedure to work. I ran the code you suggested and it worked.
I thought that the reason the procedure might have crashed was that I had my system set on British preferences, rather than US (since I’m here in the UK). I switched to US preference and re-ran the procedure including the loop with the «lastdate» and «totalsum» portions. However, it crashed again. So I still do not knmow why it it crashing.
The reason I had the arrayrange( function pulling 5-9 was simply to get a smaller sample to see if the code would work. I had planned on deleting that line of code once I had established that the procedure functioned properly.
Any help you may offer would be greatly appreciated! Thanks in advance.

Ok, so you’ll need to figure out where exactly the code is crashing. A good way to do that would be to put a stop statement near the top, run it and see if it crashes. If not, move the stop statement further down and try again. Keep doing this until you find the spot of the crash. Then we’ll at least know what spot in the program is actually causing the problem.

Aha, that makes sense.