The PSION Organiser II Homepage
Forum Home Forum Home Help Help Search Search Members Members Login Login Register Register

Welcome, Guest. Please Login or Register.
Why register?
   The Psion Organiser II Forum
   User Forum
   Help
(Moderator: Mikesan)
   OPL ARRAY VARIABLE SIZE
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: OPL ARRAY VARIABLE SIZE  (Read 6283 times)
Billirl
Member




   


Posts: 16
OPL ARRAY VARIABLE SIZE
« on: Oct 26th, 2007, 3:44pm »
Quote Quote Modify Modify

I want to set an Integer Array Variable from within the OPL program for an Organizer XP. The array size will depend on the number of items in another file in the same program. This means I want the array size to vary from program use to program use. I keep getting "Bad Array Size" as an error when I translate the procedure. I have also tried using the m1-m9 calculator memories as the array size to no avail.
Any suggestions, please?
snigfarp
Power Member




   
WWW

Posts: 78
Re: OPL ARRAY VARIABLE SIZE
« Reply #1 on: Oct 26th, 2007, 8:50pm »
Quote Quote Modify Modify

Unfortunately the size of an array has to be a constant.  I don't think the Organiser's OPL had any dynamic memory allocation functions either.  I can think of only two suggestions at the moment: (i) make the array big enough for the maximum number of items as a matter of course; or (ii) work directly from a data file - either the [other] file you mentioned, or a temporary file set up for the purpose.

Damian
http://psigamer.cyningstan.org.uk/
Billirl
Member




   


Posts: 16
Re: OPL ARRAY VARIABLE SIZE
« Reply #2 on: Oct 26th, 2007, 9:35pm »
Quote Quote Modify Modify

I am using the max array route but it gets messy and leads to entry and printing errors in the final printout. The array size dictates the size of all subsequent files in the program. It is the central product category file.
In any run I know the number of variables to be put in the array, whether it be 5 or 10 or 20 or 40 0r 50 but it would mean adjusting the program on each of 5 operating Organiser XP's and translating each in turn - a messy operation also.
snigfarp
Power Member




   
WWW

Posts: 78
Re: OPL ARRAY VARIABLE SIZE
« Reply #3 on: Oct 27th, 2007, 6:47am »
Quote Quote Modify Modify

An extra variable should help clear this up, to hold the total number of useful entries that are held in the array.  You can get this from the data file: I think there's a record count function whose name escapes me, but if not, simply increment the total each time you successfully read a record in.  Then use that total wherever you'd normally use a constant to identify the end of the array.
 
I'm not sure what printing problems you're encountering.  If you're printing to a set number of lines on the page, you need only subtract your total from the number of lines you want, printing that number of blank lines.
 
Having said all that. this sounds to me like the kind of job you want to be doing directly in the data file.

Damian
http://psigamer.cyningstan.org.uk/
Billirl
Member




   


Posts: 16
Re: OPL ARRAY VARIABLE SIZE
« Reply #4 on: Oct 27th, 2007, 10:29am »
Quote Quote Modify Modify

I run a stocktaking operation. What I wanted to do was to Declare a Global integer variable, make that variable = a COUNT function from my base product category file, which varies in size from job to job, and use that Integer variable to Declare the size of my Global Array variable. I could then prevent any extraneous entry into my main data file by comparing an entry with the Array size. I use the Array to format the final printout. I have 18 procedures in my program. I have 5 people with Organizer XPs compiling their own 3-field data files (Category, Price, Quantity) which are combined when the job is done.  
At present I print out only categories that have entries in the Product category file and therefore miss out extraneous entries which should have been corrected during the operation; but......?
« Last Edit: Oct 27th, 2007, 10:35am by Billirl »
Billirl
Member




   


Posts: 16
Re: OPL ARRAY VARIABLE SIZE
« Reply #5 on: Oct 27th, 2007, 12:21pm »
Quote Quote Modify Modify

I think what is wrong is that when I Declare the Integer variable it is automatically set at zero so that when I try to Declare the Array variable it is illegal as the Array size will be zero until the program runs. Any way out of this?
If I try to Declare the Array as VAR(1+Integer) I get a "Bad Declaration".
« Last Edit: Oct 27th, 2007, 12:31pm by Billirl »
snigfarp
Power Member




   
WWW

Posts: 78
Re: OPL ARRAY VARIABLE SIZE
« Reply #6 on: Oct 28th, 2007, 6:11am »
Quote Quote Modify Modify

Yes, I'm pretty sure there's no way to declare a variable size array.  Thinking on that LOCAL and GLOBAL have to occur before any program statements, there would never be any way to set your variable between declaring it and the array whose limits you want it to describe.  Except, that is, as a parameter.  Have you tried something like the following?
 
whatever:(size%)
GLOBAL array%(size%)
 
called with:
 
whatever:(COUNT)
 
I still think that the array bounds will have to be a constant, but it's worth a try as I can't currently check the manual to eliminate the possibility.
 
I'd wondered about reserving memory blocks too.  I checked my Series 3 manual which catalogues the changes in successive versions of OPL (my XP manual is out of reach in a box room) and even that manual had no mention of the dynamic allocation of memory blocks that I remember from somewhere.  That must have appeared in the Series 5.
 
Failing anything else, I still think the easiest way would be to continue to declare the array at the maximum expected limit, but use the size% variable as above as if it WAS the actual array bound.  It may be of course that I'm misunderstanding the problem completely.

Damian
http://psigamer.cyningstan.org.uk/
Billirl
Member




   


Posts: 16
Re: OPL ARRAY VARIABLE SIZE
« Reply #7 on: Oct 28th, 2007, 8:29pm »
Quote Quote Modify Modify

Tried using a procedure and passing on a parameter, as opposed to a variable, as I think you suggested, with the same result. I am beginning to agree with you and Boris that there is no way to solve this.
I will continue using the 'max' route.
Thanks
« Last Edit: Oct 28th, 2007, 8:33pm by Billirl »
Boris
Administrator




   
WWW

Posts: 552
Re: OPL ARRAY VARIABLE SIZE
« Reply #8 on: Oct 30th, 2007, 11:41am »
Quote Quote Modify Modify

Well, I have not yet said anything, but you're right, there is no way to declare dynamic arrays. The structure of Org2's OPL is simply not suited for such a task since variables are constructed at compile time (not at run time). All variables are turned into references to these static memory locations.
 
But it is possible to reserve a memory block by means of machine code. Before you roll your eyes, this is quite simple to do by growing the permanent cell (where the device drivers hang out).  I don't have time to write and test the 'alloc' and 'unalloc' routine right now, but I will do it tonight (or maybe tomorrow) and post them to the User Post board. I'll also post a followup here to notify you!
 
So long!
« Last Edit: Oct 30th, 2007, 11:45am by Boris »

Triholerahduliäöhh gugguh !! (tyrolean joy jodler)
Rough translation: There's a new build of Psi2Win!!
Email: boris[at]psion2[dot]org
Billirl
Member




   


Posts: 16
Re: OPL ARRAY VARIABLE SIZE
« Reply #9 on: Oct 31st, 2007, 8:31pm »
Quote Quote Modify Modify

Boris. The reason I used your name is because I found a similar reference to Arrays in another thred that you replied to some time ago.  
I would much appreciate any help you can give me but I have never used machine code. (My eyes did go towards heaven)
POISN
active Member




   


Posts: 48
Re: OPL ARRAY VARIABLE SIZE
« Reply #10 on: Nov 2nd, 2007, 2:58am »
Quote Quote Modify Modify

I had written a data collection program with which prices on products are collected. The product UPC, description, and size are stored in a data file, and the number of items in the file varies between jobs. Since updating a large data file takes a bit of time (can be over 30 seconds with a very large file, even on a RAMpak, but perhaps faster on device A:), prices are stored separately in an array (which is then written to a file). The array has to be fixed size like any OPL variable, and the first version of the program used a 2000 element array, but I later reduced it 1000 elements, since the file will not contain that many records. Hence it has a capacity for 1000 records. The array is declared with a size of 1000, but the program only uses the portion of the array that it needs and ignores the rest. Thus using subscript variables and record count variables, it will write out the price file with only as many prices as there are records in the data file. Seems to me the same method could be used with the stocktaking program. Using the equivalents of malloc and free or similar functions in C through use of machine code seems unnecessary, but perhaps I do not understand the scope of the problem.
Boris
Administrator




   
WWW

Posts: 552
Re: OPL ARRAY VARIABLE SIZE
« Reply #11 on: Nov 4th, 2007, 4:56pm »
Quote Quote Modify Modify

I have just released a toolkit for dynamic integer arrays.  
 
I have dropped the concept of using the permanent cell because of the unforseeable concequences of accidentially leftover data may have. This is the reason why it took a few days longer. However, I think this toolkit is ideal for what you want, so enjoy...
« Last Edit: Nov 4th, 2007, 4:56pm by Boris »

Triholerahduliäöhh gugguh !! (tyrolean joy jodler)
Rough translation: There's a new build of Psi2Win!!
Email: boris[at]psion2[dot]org
Billirl
Member




   


Posts: 16
Re: OPL ARRAY VARIABLE SIZE
« Reply #12 on: Nov 9th, 2007, 7:11pm »
Quote Quote Modify Modify

Sorry, I have been away for a week. Many thanks for your programs, Boris. However my eyes have hit heaven! My programming experience is limited to the Psion Organiser II Operating Manual, from which I have written an involved program. From this manual I have gleaned word definitions such as INDEX, ARRAY, PROCEDURE etc but you use words which are not defined therein and I am flummoxed. What does 'Handle' and 'Grab' mean? Why do you Declare Local mc%(4) in Array%: when you use mc%(1-9)? I do not understand the 'rem's'.  
This makes me a hopeless case but I will persevere in the hope that working through each procedure will explain what each one means.
Many thanks POISN also. My program is written almost as you describe yours with a lot of loops, error-trapping routines etc with as little in the A: memory as possible, to allow more room for records (up to 2,000). Space and speed are of paramount importance, but accuracy in data entry and subsequent analysis are even more important, especially since I know that people get tired and punch-drunk after about 5 hours entering data. (2,000 entries in 5 hrs, including counting, checking and breaks).
« Last Edit: Nov 9th, 2007, 7:25pm by Billirl »
Boris
Administrator




   
WWW

Posts: 552
Re: OPL ARRAY VARIABLE SIZE
« Reply #13 on: Nov 13th, 2007, 11:52am »
Quote Quote Modify Modify

What does 'Handle' and 'Grab' mean?
A handle is usually a number, which is used to designate an item. The number itself is meaningless to the programmer. In our case, we use handles to 'name' the dynamic arrays.
Grab is plain english: we grab some memory, i.e. we take it away from the pool of free memory.
 
Why do you Declare Local mc%(4) in Array%: when you use mc%(1-9)?
For heavens sake, did I? Thats a fault. I need to correct that. Done! I have tested the procedures with mc% as GLOBAL since this is more suitable for the emulator, so I didn't spot this one...  
 
I do not understand the 'rem's'.
I bet you don't. Most of them are the mnenonics of the machine code used. They are targeted at advanced programmers. But you don't have to. Take these routines as black boxes, you don't really need to know how they accomplish the things they are doing.
« Last Edit: Nov 13th, 2007, 12:01pm by Boris »

Triholerahduliäöhh gugguh !! (tyrolean joy jodler)
Rough translation: There's a new build of Psi2Win!!
Email: boris[at]psion2[dot]org
Prateek
Guest

Email

Re: OPL ARRAY VARIABLE SIZE
« Reply #14 on: Oct 17th, 2013, 4:40pm »
Quote Quote Modify Modify Remove Remove

Hey Boris,
 
Can you give me this toolkit? It is no longer in the attachment.
 
Thanks
Steve
active Member




   


Posts: 50
Re: OPL ARRAY VARIABLE SIZE
« Reply #15 on: Oct 17th, 2013, 5:01pm »
Quote Quote Modify Modify

Prateek,
 
Unfortunately, Boris died over a year ago, and it's only through the good offices of others that the forum is still going. However, all the links are currently dead and only time will tell if they ever go live again.
 
Steve
dtech10
active Member




   
Email

Posts: 37
Re: OPL ARRAY VARIABLE SIZE
« Reply #16 on: Oct 25th, 2013, 6:59pm »
Quote Quote Modify Modify

on Oct 26th, 2007, 3:44pm, Billirl wrote:
I want to set an Integer Array Variable from within the OPL program for an Organizer XP. The array size will depend on the number of items in another file in the same program. This means I want the array size to vary from program use to program use. I keep getting "Bad Array Size" as an error when I translate the procedure. I have also tried using the m1-m9 calculator memories as the array size to no avail.
Any suggestions, please?

 
Hi
Boris wrote some code sometime ago regarding dynamic
arrays.  
I've noticed that this says it has now been deleted in the original email which is still on this site.
I don't know if this is what your after, but I still got the zip file if its any use to you
Dtech10
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

The Psion Organiser II Forum » Powered by YaBB 1 Gold - SP 1.1!
YaBB © 2000-2002,
Xnull. All Rights Reserved.
top