creating index file for date field

Post Reply
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

creating index file for date field

Post by Ehab Samir Aziz »

creating combobox with character field goes well but I had error message of "Argument error: ALLTRIM" with date field.

Code: Select all



Local V_ct_strd:=("  /  /    ")

   @ 15, 260 COMBOBOX (V_ct_strd) ITEMS aBase1(3,"mach",256,"mc_ct_strd") size 80,80 OF oDlg PIXEL



function aBase1(workarea,cFile,xx,cField)
*--------------------------------
  local aItems:={}
  local y:=0
  aAdd(aItems,space(256)) //Put First element empty

  use (cFile) new

  index on &(cField) to temp

  go top
  do while ! eof()
     y:=ASCAN(aItems,(cFile)->&cField)
     if y==0
        aAdd(aItems,(cFile)->&cField)
        dbSkip()
        else
        dbSkip()
     endif

  enddo
  *use
  ferase("temp.ntx")
  *select(nArea)
  *use nselect
return aItems

Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post by Ehab Samir Aziz »

Please help me fixing this code :

Code: Select all

use (cFile) new
  do case 
  case VALTYPE(cField) == "D"
          tempntx:= 'DTOC(' + cField + )' 
  case VALTYPE(cField) == "N"
          tempntx:= 'str(' + cField + ')' 
  otherwise          
          tempntx:=  cField 
  endcase 
  index on &(tempntx) to temp

User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

The problem is not in the index. You have to convert dates in strings when you build the array for combobox items.

EMG
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post by Ehab Samir Aziz »

Changine the code yields the same error ;

Code: Select all

local aItems:={}
  local y:=0
  local tempntx:=""
  aAdd(aItems,space(256)) //Put First element empty

  use (cFile) new
  
  index on &(cField) to temp

  go top
  do while ! eof()
  do case 
    case VALTYPE(cField) == "D"
    		y:=ASCAN(aItems,DTOC((cFile)->&cField))
    case VALTYPE(cField) == "N"
     		y:=ASCAN(aItems,str((cFile)->&cField))
    otherwise          
     y:=ASCAN(aItems,(cFile)->&cField)
    endcase 
    
  if y==0
  do case 
      case VALTYPE(cField) == "D"
        aAdd(aItems,dtoc((cFile)->&cField))
      case VALTYPE(cField) == "N"
        aAdd(aItems,str((cFile)->&cField))
      otherwise          
       aAdd(aItems,(cFile)->&cField)
      endcase 
        dbSkip()
        else
        dbSkip()
     endif

  enddo
  *use
  ferase("temp.ntx")
  *select(nArea)
  *use nselect
return aItems
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Ehab,

You are still adding items to the array that are not string. Comboboxes can only handle string data.

Why not just do it this way:

aadd(aItems, cValToChar( (cFile)->&cField) )

Another note. If this is a multiuser application, you are likely going to get crashes since you are indexing to the same filename, 'temp.' If two people try to access this routine at the same time, the second one is going to get a crash.

James
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post by Ehab Samir Aziz »

No the same error with the code :

aadd(aItems, cValToChar( (cFile)->&cField) )

Application
===========
Path and name: E:\programs\Database\clipper\FWH\sitex\sitex.exe (32 bits)
Size: 1,691,648 bytes
Time from start: 0 hours 0 mins 17 secs
Error occurred at: 16/02/2007, 20:14:19
Error description: Error BASE/2022 Argument error: ALLTRIM
Args:
[ 1] = D 01/04/2006

Stack Calls
===========
Called from: => ALLTRIM(0)
Called from: => (b)DEFAULT(0)
Called from: => ASCAN(0)
Called from: => TCOMBOBOX:DEFAULT(0)
Called from: => TCOMBOBOX:INITIATE(0)
Called from: => __OBJSENDMSG(0)
Called from: .\source\function\HARBOUR.PRG => OSEND(0)
Called from: .\source\function\HARBOUR.PRG => ASEND(0)
Called from: => TDIALOG:INITIATE(0)
Called from: => TDIALOG:HANDLEEVENT(0)
Called from: => DIALOGBOXINDIRECT(0)
Called from: => TDIALOG:ACTIVATE(0)
Called from: sitex.prg => EDITMACH(1985)
Called from: sitex.prg => (b)LISTMACH(1649)
Called from: => TBUTTON:CLICK(0)
Called from: => TBUTTON:HANDLEEVENT(0)
Called from: .\source\classes\WINDOW.PRG => _FWH(0)
Called from: => SENDMESSAGE(0)
Called from: => TDIALOG:COMMAND(0)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: => TDIALOG:HANDLEEVENT(0)
Called from: => DIALOGBOXINDIRECT(0)
Called from: => TDIALOG:ACTIVATE(0)
Called from: sitex.prg => LISTMACH(1664)
Called from: sitex.prg => (b)BUILDMENU(160)
Called from: => TMENU:COMMAND(0)
Called from: => TWINDOW:COMMAND(0)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: .\source\classes\WINDOW.PRG => _FWH(0)
Called from: => WINRUN(0)
Called from: => TWINDOW:ACTIVATE(0)
Called from: sitex.prg => MAIN(134)
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Ehab,

>No the same error with the code :

>aadd(aItems, cValToChar( (cFile)->&cField) )

I don't know exacly how you coded it, but your error message is saying that there are still date values in the aItems array. Please show us your revised code.

James
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Ehab,

Code: Select all

  do case 
      case VALTYPE(cField) == "D" 
        aAdd(aItems,dtoc((cFile)->&cField)) 
      case VALTYPE(cField) == "N" 
        aAdd(aItems,str((cFile)->&cField)) 
      otherwise          
       aAdd(aItems,(cFile)->&cField) 
      endcase 
This line is wrong:

Code: Select all

      case VALTYPE(cField) == "D" 
It will always be C since you are asking for the valtype() of the value in the var cField, which is the fieldname not the value of the data in the field.

However you just need to remove ALL of the DO CASE and replace it with the line I gave you:

Code: Select all

   aadd(aItems, cValToChar( (cFile)->&cField) ) 
This handles all datatypes.

James
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post by Ehab Samir Aziz »

Oka I got it .

Code: Select all


..
V_ct_strd   :=dtoc(mach->MC_CT_strd)
V_ct_endd   :=dtoc(mach->MC_CT_endd)
V_MC_indate :=dtoc(mach->MC_indate)

..
..
@ 15, 190 COMBOBOX (V_ct_strd) ITEMS aBase1(3,"mach",256,"mc_ct_strd") size 80,80 OF oDlg PIXEL


function aBase1(workarea,cFile,xx,cField)
*--------------------------------
  local aItems:={}
  local y:=0
  local tempntx:=""
  aAdd(aItems,space(256)) //Put First element empty

  use (cFile) new
  
  index on &(cField) to temp

  go top
  do while ! eof()
  
  y:=ASCAN(aItems, (cFile)->&cField)
  		
      
   
  if y==0
  
  
      	    aadd(aItems, cValToChar( (cFile)->&cField) ) 

        dbSkip()
        else
        dbSkip()
     endif

  enddo
  *use
  ferase("temp.ntx")
  *select(nArea)
  *use nselect
return aItems
BUT Still this line below cause not dates to be unique .

The code working good accept this line below . I mean dates are repeated which is not required .

Code: Select all

y:=ASCAN(aItems,(cFile)->&cField)
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Ehab,

You also need to change that line:

Code: Select all

 y:=ASCAN(aItems, cValToChar( (cFile)->&cField ) ) 
You can also eliminate the indexing of the DBF and then just sort the array after it is filled.

Code: Select all

aItems:= Asort( aItems )

James
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post by Ehab Samir Aziz »

editmach module goes well with with lAppend=.f. (update option ) but with lAppend=.t. (New record) I had the alltrim argument error message.

Code: Select all

static function Editmach(oLbx,lAppend)
//------------------------------------------
..
Local V_ct_strd:=ctod("  /  /    ")
Local V_ct_endd:=ctod("  /  /    ")
..
   DEFAULT lAppend := .f.
..
if lAppend
   GOTO BOTTOM
   SKIP
else
   goto nOldRec
V_ct_strd   :=dtoc(mach->MC_CT_strd)
V_ct_endd   :=dtoc(mach->MC_CT_endd)

endif




   DEFINE DIALOG oDlg FROM 0, 0 TO 650, 1000 PIXEL;
      TITLE If( lAppend, "New Machine", "Machine Update" )


   @ 1,1 SAY "&Account No." OF oDlg PIXEL
   @ 1,50 SAY ":" OF oDlg PIXEL 
   @ 1,60 COMBOBOX V_CU_ACCT ITEMS aBase1(3,"mach",256,"mc_cu_acct") size 80,80 OF oDlg PIXEL


   @ 1,150 SAY "&Name" OF oDlg PIXEL
   @ 1,180 SAY ":" OF oDlg PIXEL
   @ 1,190 COMBOBOX V_CU_NAME ITEMS aBase1(3,"mach",256,"mc_cu_name") size 150,120 OF oDlg PIXEL


   @ 15, 1 SAY "Contract Name" OF oDlg PIXEL
   @ 15, 50 SAY ":" OF oDlg PIXEL
   @ 15,60 COMBOBOX V_ct_ctna ITEMS aBase1(3,"mach",256,"mc_ct_ctna") size 80,80 OF oDlg PIXEL

   @ 15, 150 SAY "Start Date" OF oDlg PIXEL
   @ 15, 180 SAY ":" OF oDlg PIXEL
   @ 15, 190 COMBOBOX (V_ct_strd) ITEMS aBase1(3,"mach",256,"mc_ct_strd") size 80,80 OF oDlg PIXEL


   @ 15, 300 SAY "End Date" OF oDlg PIXEL
   @ 15, 350 SAY ":" OF oDlg PIXEL
   @ 15, 360 COMBOBOX (V_ct_endd) ITEMS aBase1(3,"mach",256,"mc_ct_endd") size 80,80 OF oDlg PIXEL
..
..
Post Reply