Page 1 of 1

check if list has a no?

PostPosted: Thu Sep 04, 2014 7:30 am
by yanzco
hello..

i have a table..
every item, it adds a yes or no..

i need a checker if the table has a single no in it..

i made this subroutine called OUTchecker
it checks if all items are out.. or not..

but it seems this code of mine, is only able to check the last item..
i need it to check every field so i can determine if it is complete or in progress..


Code: Select all
dbpQuery "Hexdb" "SOD" "InvoiceNumber = [#34][VTInvoiceNumber][#34]"
SetVar "[translistcount]" "[Hexdb.SOD.$RecCount]"
dbpFirst "Hexdb" "SOD"
Loop "1" "[translistcount]" "[looper]"
If "[Hexdb.SOD.out]" "=" "[Hexdb.SOD.Quantity]"
SetVar "[CompleteOUT]" "YES"
dbpNext "Hexdb" "SOD"
Else
SetVar "[CompleteOUT]" "NO"
dbpNext "Hexdb" "SOD"
EndIf
EndLoop

If "[CompleteOUT]" "=" "YES"
SetVar "[VtsStatus]" "Complete"
SetVar "[Hexdb.Sales.sStatus]" "Complete"
dbpSaveEdits "Hexdb" "Sales"
Else
If "[CompleteOUT]" "=" "NO"
SetVar "[VtsStatus]" "In Progress"
SetVar "[Hexdb.Sales.sStatus]" "In Progress"
dbpSaveEdits "Hexdb" "Sales"
Else
Endif
EndIf
Return

Re: check if list has a no?

PostPosted: Thu Sep 04, 2014 8:06 am
by Gaev
yanzco:

Since you are updating [CompleteOUT] for each record, the value from each successive record over-writes the value from the previous record.

Try this code ...
Code: Select all
dbpQuery "Hexdb" "SOD" "InvoiceNumber = [#34][VTInvoiceNumber][#34]"
SetVar "[translistcount]" "[Hexdb.SOD.$RecCount]"
dbpFirst "Hexdb" "SOD"

SetVar "[CompleteOUT]" "YES"

Loop "1" "[translistcount]" "[looper]"
   If "[Hexdb.SOD.out]" "=" "[Hexdb.SOD.Quantity]"
      dbpNext "Hexdb" "SOD"
   Else
      SetVar "[CompleteOUT]" "NO"
      dbpNext "Hexdb" "SOD"
   EndIf
EndLoop


So it starts out with a value of "YES" ... and only changes to "NO" when one of the records with a mismatch is found.

Also, if you are only interested to know if "there is at least one mismatch" ... you can use ExitLoop like this ...
Code: Select all
dbpQuery "Hexdb" "SOD" "InvoiceNumber = [#34][VTInvoiceNumber][#34]"
SetVar "[translistcount]" "[Hexdb.SOD.$RecCount]"
dbpFirst "Hexdb" "SOD"

SetVar "[CompleteOUT]" "YES"

Loop "1" "[translistcount]" "[looper]"
   If "[Hexdb.SOD.out]" "=" "[Hexdb.SOD.Quantity]"
      dbpNext "Hexdb" "SOD"
   Else
      SetVar "[CompleteOUT]" "NO"
      ExitLoop
   EndIf
EndLoop


Finally, you can do all this directly within the dbpQuery command like this ...
Code: Select all
dbpQuery "Hexdb" "SOD" "InvoiceNumber = [#34][VTInvoiceNumber][#34] AND out <> Quantity"
If "[Hexdb.SOD.$RecCount]" "=" "0"
   ... no mismatches
Else
   ... one or more mismatches

EndIf

Re: check if list has a no?

PostPosted: Thu Sep 04, 2014 8:14 am
by mishem
Especially not penetrate, but from the provided code can see that.

Code: Select all
dbpQuery "Hexdb" "SOD" "InvoiceNumber = [#34][VTInvoiceNumber][#34]"
     SetVar "[translistcount]" "[Hexdb.SOD.$RecCount]"
     dbpFirst "Hexdb" "SOD"
    Loop "1" "[translistcount]" "[looper]"
       If "[Hexdb.SOD.out]" "=" "[Hexdb.SOD.Quantity]"
           SetVar "[CompleteOUT]" "YES"
           SetVar "[VtsStatus]" "Complete"
           SetVar "[Hexdb.Sales.sStatus]" "Complete"
         Else
            SetVar "[CompleteOUT]" "NO"
            SetVar "[VtsStatus]" "In Progress"
            SetVar "[Hexdb.Sales.sStatus]" "In Progress"
       EndIf
       dbpSaveEdits "Hexdb" "Sales"
       dbpAddRecord "Hexdb" "Sales"
       dbpNext "Hexdb" "SOD"
    EndLoop
Return

Re: check if list has a no?

PostPosted: Thu Sep 04, 2014 6:59 pm
by yanzco
thanks gaev! that worked.. didnt know it was that easy.. :lol: