FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour creating index file for date field
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
creating index file for date field
Posted: Fri Feb 16, 2007 11:25 AM
creating combobox with character field goes well but I had error message of "Argument error: ALLTRIM" with date field.
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: creating index file for date field
Posted: Fri Feb 16, 2007 11:45 AM

You have to convert dates to strings using DTOC().

EMG

Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
creating index file for date field
Posted: Fri Feb 16, 2007 12:43 PM
Please help me fixing this code :
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
creating index file for date field
Posted: Fri Feb 16, 2007 02:12 PM

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

EMG

Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
creating index file for date field
Posted: Fri Feb 16, 2007 05:10 PM
Changine the code yields the same error ;
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
creating index file for date field
Posted: Fri Feb 16, 2007 05:59 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
creating index file for date field
Posted: Fri Feb 16, 2007 06:15 PM

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)

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
creating index file for date field
Posted: Fri Feb 16, 2007 06:22 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
creating index file for date field
Posted: Fri Feb 16, 2007 06:32 PM
Ehab,

  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:

      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:

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


This handles all datatypes.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
creating index file for date field
Posted: Fri Feb 16, 2007 08:43 PM
Oka I got it .

..
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 .

y:=ASCAN(aItems,(cFile)->&cField)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
creating index file for date field
Posted: Fri Feb 16, 2007 10:25 PM
Ehab,

You also need to change that line:

 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.

aItems:= Asort( aItems )



James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
creating index file for date field
Posted: Sat Feb 17, 2007 08:48 AM
editmach module goes well with with lAppend=.f. (update option ) but with lAppend=.t. (New record) I had the alltrim argument error message.

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
..
..

Continue the discussion