Subject Re: ApplyLocate error
From Ruth Bromer <ruth@treklite.com>
Date Wed, 17 Jul 2019 11:06:47 -0400
Newsgroups dbase.getting-started
Attachment(s) Packet.DBFscreener.prgscreenerOriginal.prgt_orders.DBFTShirtSorted.dbf

So far I can't get any suggestions to fix the problem.  The data going
into my 'if' statement is correct.  (displayed the data for each record
in testing.)  But for some reason the 'if' statement isn't valid in the
new Screener.prg but is in the original ScreenerOriginal.prg.

I haven't changed the field names in the T_orders table.  I replaced the
fields in Packet.dbf with those in TShirtSorted.dbf.  No problem there.
I didn't modify the 'if' statement which should have all of the same
information going into it.

I just can't see it.  And I need to get the report out today (east coast
of the US).  I can probably push it to tomorrow or I'm going to have to
print what I can and modify the report by hand which I really don't want
to do.)

Ruth

On 7/16/2019 8:23 PM, Ruth Bromer wrote:
> I have a program to create a table to be used to create a report for the
> shirt screener. (Mervyn wrote the original program with some
> modifications from me.)
>
> Since I have to add a few shirt orders that aren't coming from my input
> csv file, I am adding them to the input file and then resorting the
> output table (TShirtSorted.dbf).
>
> The original Screener.prg uses the table, Packet.dbf as input.  I want
> to use the TShirtSorted.dbf as input.  They both have the same relevant
> fields, shirt size and shirt color.  Most of the code is the same.
>
> The error message is:
>
> Database Engine Error: Operation not appicable.
> FIle:  Screener.prg
> Routine: SCREENER
> Line:   70
>
> Where the program crashes is with the ApplyLocate command (line 70).
>
> if not  t_orders1.rowset.applyLocate( "t_size = '" + cSize+ "' and
> t_color = '" + cColor +"'"  )
>
> The fields cSize and cColor both have valid data.
>
> ScreenerOriginal.prg is the original and screener.prg is my new version.
>
> Ruth




if file('t_orders.dbf')
drop table t_orders
endif

if not file('t_orders.dbf')
   create table t_orders  (id autoinc, t_size_order numeric (2),;
   t_size character(13),t_color character(8),qty numeric(10))
endif

tshirt1 = new query()
tshirt1.sql = 'select * from TShirtSorted where quantity > 0  order by shirtsize,color'
tshirt1.active = true

t_orders1 = new query()
t_orders1.sql =  'select * from t_orders'
t_orders1.active = true

do while not tshirt1.rowset.endofset
   cColor = tshirt1.rowset.fields['Color'].value

        if tshirt1.rowset.fields['ShirtSize'].value = 'XXS'
                cSize = 'XX-Small'
                cSizeOrder = 1
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'XS'
                cSize = 'X-Small'
                cSizeOrder = 2
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'SM'
                cSize = 'Small'
                cSizeOrder = 3
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'MD'
                cSize = 'Medium'
                cSizeOrder = 4
   elseif tshirt1.rowset.fields['ShirtSize'].value = 'LG'
                cSize = 'Large'
                cSizeOrder = 5
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'XL'
                cSize = 'X-Large'
                cSizeOrder = 6
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'XXL'
                cSize = 'XX-Large'
                cSizeOrder = 7
        elseif tshirt1.rowset.fields['ShirtSize'].value = '3XL'
                cSize = '3X-Large'
                cSizeOrder = 8
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'YS'
                cSize = 'Youth Small'
                cSizeOrder = 9
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'YM'
                cSize = 'Youth Medium'
                cSizeOrder = 10
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'YL'
                cSize = 'Youth Large'
                cSizeOrder = 11
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'WS'
                cSize = 'Women Small'
                cSizeOrder = 12
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'WM'
                cSize = 'Women Medium'
                cSizeOrder = 13
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'WL'
                cSize = 'Women Large'
                cSizeOrder = 14
        elseif tshirt1.rowset.fields['ShirtSize'].value = 'WXL'
                cSize = 'Women X-Large'
                cSizeOrder = 15
        endif
        
        nQty = tshirt1.rowset.fields['Quantity'].value

        if not  t_orders1.rowset.applyLocate( "t_size = '" + cSize+ "' and t_color = '" + cColor +"'"  )
      //no record in _ordered table.  Add it
      t_orders1.rowset.beginAppend()
      t_orders1.rowset.fields['t_size' ].value = cSize
      t_orders1.rowset.fields['t_size_order' ].value = cSizeOrder
                t_orders1.rowset.fields['t_color' ].value = cColor
      t_orders1.rowset.fields['qty' ].value = nQty
      t_orders1.rowset.save()
   elseif   t_orders1.rowset.applyLocate( "t_size = '" +cSize +"' and t_color = '"+cColor +"'" )
      //size and color already in table. Increment count.
      t_orders1.rowset.fields['qty' ].value += nQty
      t_orders1.rowset.save()        
   elseif   t_orders1.rowset.applyLocate( "t_size = '" +cSize +"' and not t_color = '"+cColor+"'"  )
      // size  already in t_orders table but not color. Add it
      t_orders1.rowset.beginAppend()
      t_orders1.rowset.fields['t_size' ].value = cSize
      t_orders1.rowset.fields['t_size_order' ].value = cSizeOrder
                t_orders1.rowset.fields['t_color' ].value = cColor
      t_orders1.rowset.fields['qty' ].value = nQty
      t_orders1.rowset.save()
   elseif  not  t_orders1.rowset.applyLocate( " t_size = '" +cSize +"'"  )    
      //size not in table.  Add it
      t_orders1.rowset.beginAppend()
      t_orders1.rowset.fields['t_size' ].value = cSize
      t_orders1.rowset.fields['t_size_order' ].value = cSizeOrder
                t_orders1.rowset.fields['t_color' ].value = cColor
      t_orders1.rowset.fields['qty' ].value = nQty
      t_orders1.rowset.save()
   endif
        
   tshirt1.rowset.next()
enddo
  
tshirt1.active = false
t_orders1.active = false
msgbox( "The T_orders table should now have data in it" )



if file('t_orders.dbf')
drop table t_orders
endif

if not file('t_orders.dbf')
   create table t_orders  (id autoinc, t_size_order numeric (2),;
   t_size character(13),t_color character(8),qty numeric(10))
endif

tshirt1 = new query()
tshirt1.sql = 'select * from packet where tshirtquant > 0 order by tshirtsize,tshirtcolor'
tshirt1.active = true

t_orders1 = new query()
t_orders1.sql =  'select * from t_orders'
t_orders1.active = true

do while not tshirt1.rowset.endofset
   cColor = tshirt1.rowset.fields['TshirtColor'].value

        if tshirt1.rowset.fields['TshirtSize'].value = 'XXS'
                cSize = 'XX-Small'
                cSizeOrder = 1
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'XS'
                cSize = 'X-Small'
                cSizeOrder = 2
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'SM'
                cSize = 'Small'
                cSizeOrder = 3
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'MD'
                cSize = 'Medium'
                cSizeOrder = 4
   elseif tshirt1.rowset.fields['TshirtSize'].value = 'LG'
                cSize = 'Large'
                cSizeOrder = 5
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'XL'
                cSize = 'X-Large'
                cSizeOrder = 6
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'XXL'
                cSize = 'XX-Large'
                cSizeOrder = 7
        elseif tshirt1.rowset.fields['TshirtSize'].value = '3XL'
                cSize = '3X-Large'
                cSizeOrder = 8
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'YS'
                cSize = 'Youth Small'
                cSizeOrder = 9
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'YM'
                cSize = 'Youth Medium'
                cSizeOrder = 10
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'YL'
                cSize = 'Youth Large'
                cSizeOrder = 11
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'WS'
                cSize = 'Women Small'
                cSizeOrder = 12
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'WM'
                cSize = 'Women Medium'
                cSizeOrder = 13
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'WL'
                cSize = 'Women Large'
                cSizeOrder = 14
        elseif tshirt1.rowset.fields['TshirtSize'].value = 'WXL'
                cSize = 'Women X-Large'
                cSizeOrder = 15
        endif
        
        nQty = tshirt1.rowset.fields['TshirtQuant'].value
        
   if not  t_orders1.rowset.applyLocate( "t_size = '" + cSize+ "' and t_color = '" + cColor +"'"  )
      //no record in _ordered table.  Add it
      t_orders1.rowset.beginAppend()
      t_orders1.rowset.fields['t_size' ].value = cSize
      t_orders1.rowset.fields['t_size_order' ].value = cSizeOrder
                t_orders1.rowset.fields['t_color' ].value = cColor
      t_orders1.rowset.fields['qty' ].value = nQty
      t_orders1.rowset.save()
   elseif   t_orders1.rowset.applyLocate( "t_size = '" +cSize +"' and t_color = '"+cColor +"'" )
      //size and color already in table. Increment count.
      t_orders1.rowset.fields['qty' ].value += nQty
      t_orders1.rowset.save()        
   elseif   t_orders1.rowset.applyLocate( "t_size = '" +cSize +"' and not t_color = '"+cColor+"'"  )
      // size  already in t_orders table but not color. Add it
      t_orders1.rowset.beginAppend()
      t_orders1.rowset.fields['t_size' ].value = cSize
      t_orders1.rowset.fields['t_size_order' ].value = cSizeOrder
                t_orders1.rowset.fields['t_color' ].value = cColor
      t_orders1.rowset.fields['qty' ].value = nQty
      t_orders1.rowset.save()
   elseif  not  t_orders1.rowset.applyLocate( " t_size = '" +cSize +"'"  )    
      //size not in table.  Add it
      t_orders1.rowset.beginAppend()
      t_orders1.rowset.fields['t_size' ].value = cSize
      t_orders1.rowset.fields['t_size_order' ].value = cSizeOrder
                t_orders1.rowset.fields['t_color' ].value = cColor
      t_orders1.rowset.fields['qty' ].value = nQty
      t_orders1.rowset.save()
   endif
        
   tshirt1.rowset.next()
enddo
  
tshirt1.active = false
t_orders1.active = false
msgbox( "The T_orders table should now have data in it" )