Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Want to remove the last two rows of an array
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00477183
Message ID:
00477197
Vues:
30
Hi Brenda

I think you mean columns, so I'll work on that assumption for the rest of this answer.

There are at least a couple of ways you can do this
  1. Get a list of the field names you need and build the SELECT clause of an SQL statement, then execute the statement using macro expansion
  2. loop through the array and copy the elements other than the last two in each row out into another array

If you choose number 1, you could use something like
local lnField, laFields[1], lcSelect, lcSQL
lcSelect = ''
select (cAlias)
* get a list of the fields (except the last two)
* if this isn't the first field in the list, add a <comma space> before adding the field name
for lnField = 1 to afields(laFields) - 2
  lcSelect = lcSelect + iif(empty(lcSelect), '', ', ') + laFields[lnField, 1]
endfor

* generate the SQL statement
lcSQL = [SELECT ] + lcSelect + [ FROM (cAlias) ] + ;
  [WHERE ALLTRIM(USER_ID) = ALLTRIM(User) ] + ;
  [and alltrim(lettername) = alltrim(letters.lettername) ] + ;
  [into array RT_LETTR]

* execute the SQL statement
&lcSQL.
For number two, just create an array 2 columns narrower and loop through, copying contents across:
select(cAlias)
* get all of the fields into an array
select * ;
  from (cAlias) ;
  where ALLTRIM(USER_ID) = ALLTRIM(User) and alltrim(lettername) = alltrim(letters.lettername) ;
  into array tempArray

* create an array with the same number of rows, but with two fewer columns
dimension RT_LETTR[alen(tempArray, 1), alen(tempArray, 2) - 2)

* copy each element from the source array (less the last two columns)
* to the corresponding element in the target array
for lnRow = 1 to alen(tempArray, 1)
  for lnColumn = 1 to alen(tempArray, 2) - 2
    RT_LETTR[row, column] = tempArray[row, column]
  endfor
endfor

* erase the (temporary) source array
release tempArray
Note that I haven't had time to set up your environment to test this, so there may be a typo lurking somewhere - it should be enough to give you an idea or two though.

Cheers,

Andrew

>SELECT (calias)
>SCAN FOR ALLTRIM(USER_ID) = ALLTRIM(User) and alltrim(lettername) = alltrim(letters.lettername)
>SCATTER TO A_Temp
>INSERT INTO RT_LETTR FROM ARRAY A_Temp
>ENDSCAN
>
>Is some existing code that works. Except the last two rows (i always get columns and rows confused. i want to delete two from the first subscript) of calias contain fields user and lettername which are really just in the table for programming. They should not be inserted into RT_LETTR. So I would like to prevent the last two rows of calias from being inserted into RT_LETTR. calias is built with a STRUCTURE and never has the same number of rows or the same table column names.
>
>Thanks
>
>Brenda


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform