Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Initialize an empty array for a listbox
Message
 
À
30/03/2004 12:30:52
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00890882
Message ID:
00890906
Vues:
19
>VFP 7, array is property of the form.
>
>I am trying update an application and want to create a list box which is populated by an array for a SQL select command. The first time it is used it is empty and it displays ".F." which make sense since there is nothing to display yet. The problems:
>
>1. not a good thing for users to see so I would like to display a blank line.
>2. I assume it is related to fact that there is no array, but if I try to add to the array I get an array out of bound message.
>
>What is the best way to avoid both problems.
>
>TIA for any help.

Why not initialize the first array element with empty string, for example in form.Init() like in this sample?
**************************************************
*-- Form:         form1 (c:\z\formlist.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   03/30/04 02:11:00 PM
*
DEFINE CLASS form1 AS form


	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	DIMENSION aarray[1]


	ADD OBJECT list1 AS listbox WITH ;
		RowSourceType = 5, ;
		RowSource = "thisform.aarray", ;
		Height = 133, ;
		Left = 48, ;
		Top = 36, ;
		Width = 145, ;
		Name = "List1"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 60, ;
		Left = 240, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"


	PROCEDURE Init
* initialize the array element so it will show as empty
		thisform.aarray(1) = ""
	ENDPROC


	PROCEDURE command1.Click
* substitute with your table here
		select name from mytable into array thisform.aarray
		thisform.list1.requery()
		thisform.list1.refresh()
	ENDPROC


ENDDEFINE
I guess you have the reasons not to use the SQL Select directly as RowSourceType, right?
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform