Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not an array 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have
Code:
DIMENSION PTYPE(3)
PTYPE[1] = 'htm'
PTYPE[2] = 'html'
PTYPE[3] = 'shtml'
in the load event of a form

controlsource is set to m.ext to reflect a field of the storage table.
Rowsource is set to PTYPE
Rowsourcetype is set to array

run the form and it errors saying PTYPE is not an array.

This was working OK at first and then at some point I started getting the error.
What am I doing wrong?

Keith
 
Variable scope.

If you create ptype in the command window, it may have been public, therefore working.
Waht you create in any event the way you do is private, and private variable scope ends at end ofthe event, therefore the array doesn't exist after Load.

With three such simple elements it would be rowsourcetype = 1 and rowsource "htm,html,shtml" and that's it.

Anyway, better forget about standalone arrays. If you still want an array rowsource type you can use ACOPY() to copy this array after it's creation to a form property and persist it that way or you may use an array property in the first place.

Bye, Olaf.
 
Keith, the code that you have shown is simply creating an array as a local variable. Once the Load event terminates, the array will go out of scope. Hence the message that you saw.

What you need to do is to create an array property. You can do that in the Form Designer, in the same way that you create any other custom property, except that you add a number in square brackets after the name, for example: PTYPE[3]

You then reference the array elements as THISFORM.PTYPE[1], etc. To set the rowsource (I assume you are referring to a list box or combo box here):

THISFORM.Listbox1.RowSource = "THISFORM.PTYPE"

Note the quotes around the array name.

I think that should solve the problem.

Mike









__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for both of those.
I assumed that declaring something in the load property meant that it persisted throughout the form, I learn something new every day.
The simple solution of the 3 items in the rowsource works ok for me

Keith
 
you could implement the above advise in your original code

Code:
thisform.addproperty(PTYPE[3],'htm')
PTYPE[2] = 'html'
PTYPE[3] = 'shtml'


nasib
 
I learn something new every day.

And the irony is that it isn't new at all.

Code:
Function MyFunction
  Dimension MyArray[3]

Can you reference that array outside of the function that declares it? No. You can reference it in lower level called programs, because it has the default scope (private), but once your function ends it goes out of scope.

Form methods behave exactly the same way. Absolutely nothing has changed. It's just slightly different packaging.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top