Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ListBox show Elements but not .F. when nothing to be sho
Message
From
04/06/2018 03:36:23
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
04/06/2018 01:37:57
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01660530
Message ID:
01660532
Views:
78
>Hi,
>
>I have a listbox, populated with an array: Thisform.aNames
>The list is restricted to the first 10 elements only so NumberOfElements is set 10
>The array is constructed in myForm with aNames[10,2]
>
>and populated with a select:
Select naw.fullname, naw.ID from NAW where  substring(fullname,1) = ? m.lcLetter into array aNames[10.2]
>this works fine, however, when there is not enough data to populate 10 fields the remaing are shown in the listbox as .F., how should I change to avoid this, prefer to show [ ] (nothing)

Honestly I don't understand how that really works in the first place. I just tested thinking I might be wrong but that kind of syntax is giving me error ("SQL: Statement is invalid"). You can't really specify the array size, can you?
Whatever the initial size of an array is, after the select statement it would be [selected rows count, columns count].
Local array laCheck1[300,100], laCheck2[1]
Select * from (_samples+'data\customer') into array laCheck1
Select * from (_samples+'data\customer') into array laCheck2

? Alen(laCheck1,1), Alen(laCheck1,2)
? Alen(laCheck2,1), Alen(laCheck2,2)
The only exception to this is when select doesn't return any rows. Then the array's original size and values ae preserved.

You could do a select into array with top to limit to 10 and then use _Tally to set the NumberOfElements.

My preference would be to use a RowSourceType of 3-SQL and RowSource:
Select top 10 fullname, ID from NAW where  fullname like ?m.lcLetter + '%' order by 1 into cursor crsMyNames
Example:
Select * From (_samples+"data\customer") Into Cursor NAW nofilter

Public oForm
oForm = Createobject('MyForm')
oForm.Show()

Define Class MyForm As Form
	Add Object myList As ListBox With Top = 10, Left=10, Height = 200

	Procedure myList.Init
		Local lcLetter
		lcLetter = 'B'

		This.RowSourceType=3
		TEXT to this.RowSource pretext 1+2+4+8 noshow
Select top 10 Company, Cust_id
from NAW
where Company like ?m.lcLetter + '%'
order by 1
into cursor crsMyNames
		ENDTEXT

	Endproc
Enddefine
Using SQL rowsource's advantages come for free then (such as accessing the ID field -typed- simply by using alias.Id).
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform