creating index file for date field

creating index file for date field

Postby Ehab Samir Aziz » 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.
Code: Select all  Expand view


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

Re: creating index file for date field

Postby Enrico Maria Giordano » Fri Feb 16, 2007 11:45 am

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

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

Postby Ehab Samir Aziz » Fri Feb 16, 2007 12:43 pm

Please help me fixing this code :
Code: Select all  Expand view
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

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

Postby Enrico Maria Giordano » Fri Feb 16, 2007 2: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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Ehab Samir Aziz » Fri Feb 16, 2007 5:10 pm

Changine the code yields the same error ;
Code: Select all  Expand view
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
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby James Bott » Fri Feb 16, 2007 5: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Ehab Samir Aziz » Fri Feb 16, 2007 6: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)
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby James Bott » Fri Feb 16, 2007 6: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Fri Feb 16, 2007 6:32 pm

Ehab,

Code: Select all  Expand view
  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  Expand view
      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  Expand view
   aadd(aItems, cValToChar( (cFile)->&cField) )


This handles all datatypes.

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

Postby Ehab Samir Aziz » Fri Feb 16, 2007 8:43 pm

Oka I got it .

Code: Select all  Expand view

..
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  Expand view
y:=ASCAN(aItems,(cFile)->&cField)
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby James Bott » Fri Feb 16, 2007 10:25 pm

Ehab,

You also need to change that line:

Code: Select all  Expand view
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  Expand view
aItems:= Asort( aItems )



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

Postby Ehab Samir Aziz » Sat Feb 17, 2007 8: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.

Code: Select all  Expand view
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
..
..
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests