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!

dealing with array returning false(.F.)

Status
Not open for further replies.

thegame8311

Technical User
Jan 6, 2012
133
US
hopefully this one is easier

I understand that when an array is empty it stores a .F. as the first element, since I have this set up in a listbox display, I don't want it to display .F. in the listbox. I can seem to find an if statement that works with the following code.

If the array returns .F. I want nothing to display in the listbox

Note: there are declared variables for the below code
Code:
FOR I = 1 TO Recnums
	SELECT Player FROM (mTeams[I]) WHERE Player = (PName) INTO ARRAY Pary

		Sary = Pary
	IF ALEN(Sary) > 0
		thisform.list1.RowSourceType = 5
		thisform.list1.RowSource = 'Sary'
		thisform.list1.ColumnCount = 1
		thisform.list1.ColumnWidths = "100" 
	ENDIF 
	IF ALEN(Pary) = 0
		thisform.list1.RowSourceType = 1
		thisform.list1.RowSource = "Player"
		thisform.list1.ColumnCount = 1
		thisform.list1.ColumnWidths = "100"
	ENDIF
ENDFOR
 
TheGame8311

Hi,

it seems to me that your
Code:
SELECT Player FROM (mTeams[I]) WHERE Player = (PName) INTO ARRAY Pary
is not correct, you cannot 'select form an array' you can only select from a table or cursor.

furthermore, it seems to me that your logic to load your controlsource for the listbox load is also not correct.

Assuming your table is called teams
you can do:

Code:
select player form teams where player = m.Pname into cursor curListSource
now you can feed your listbox with cursor curListSource

Regards,

Jockey(2)
 
The table name to select from is stored in the array, so I am using it as a variable
 
VFP doesn't support empty arrays, so if there's no data, you need to put something, maybe the empty string, into the first element.

Code:
IF _TALLY = 0
   DIMENSION Pary[1]
   Pary[1]=""
ENDIF

Incidentally, it's not a good idea to use variables declared elsewhere like that. It's better to use form properties or properties of the controls themselves.

Tamar
 
Sary=Pary doesan't work as array copy, Sary will just be Pary[1]. A rowsource of Saly also will not work for that matter. Check out ACOPY and copy to a form or listbox property to make it hold the array during the lifetime scope of the control. You could only display private or public variables/arrays in controls and this is not what I'd recommend. We have cursors for data binding, the need for something else is rare.

Also you again have a list of tables, which should be one instead. The players table would have a teamid or teamnumber field, with which you put players into teams. You're way too often putting data into several tables to seperate them.

You could select from players where teamid = ... into cursor ...

Like Tamar indirectly said _TALLY tells you the number of records a query resulted in, but with the destination of a cursor you can get an empty cursor, while an array always will have at least one element.

Bye, Olaf.

 
As Olaf says - Also you again have a list of tables

Rather than continuing to attempt to find ways to resolve issues resulting from situations like this, you should go back and re-architect the entire application's data tables.

Yes that would mean changing a lot of your existing code, but you would have a MUCH better design and issues like this and the many others you have had questions about would be eliminated.

Good Luck,
JRB-Bldr
 
issues like this and the many others you have had questions about would be eliminated.

Agree on re-architecting the table structures, but the empty array issue will NEVER go away.
 
Thegame8311

sorry, my first answer was to hasty, maybe due to the fact that this type of coding is not usual. Anyway;

Code:
Select Player From (mTeams[I]) Where Player = (PName) Into Array Pary
Acopy(Sary,Pary)
Thisform.list1.ColumnCount = 1
Thisform.list1.ColumnWidths = "100"
	
If _tally > 0
        Thisform.list1.RowSourceType = 5
	Thisform.list1.RowSource = 'Sary'
Else
	Thisform.list1.RowSourceType = 1
	Thisform.list1.RowSource = "Player"
Endif

should work, although I am not in favor of such a piece of coding.

Please note:
The loop FOR I = 1 TO Recnums is not correct, the select statement gives you all the records according to the where clause. In your case with a loop you will endup with an array, overwriting the previoys array, of only one last record or in case your last record does not comply with the where you get an empty array. In VFP an empty array = an array with 1 element which is .F. so the use of _tally is in this case more reliable.

Why is there a udf recnums? reccount() is reliable also the use of a rename of the array Pary to Sary makes me wonder.

Regards,

Jockey(2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top